Android布局属性大全

来源:互联网 发布:办公室小野 知乎 编辑:程序博客网 时间:2024/05/16 14:44

ViewGroup.LayoutParams

XML Attributes

Attribute Name

Related Method

Description

android:layout_height

 

Specifies the basic height of the view. 

android:layout_width

 

Specifies the basic width of the view. 

 

ViewGroup.LayoutParams

ViewGroup.MarginLayoutParams

 

XML Attributes

Attribute Name

Related Method

Description

android:layout_marginBottom

setMargins(int,int,int,int)

Specifies extra space on the bottom side of this view. 

android:layout_marginEnd

setMarginEnd(int)

Specifies extra space on the end side of this view. 

android:layout_marginLeft

setMargins(int,int,int,int)

Specifies extra space on the left side of this view. 

android:layout_marginRight

setMargins(int,int,int,int)

Specifies extra space on the right side of this view. 

android:layout_marginStart

setMarginStart(int)

Specifies extra space on the start side of this view. 

android:layout_marginTop

setMargins(int,int,int,int)

Specifies extra space on the top side of this view. 

 

ViewGroup.LayoutParams

ViewGroup.MarginLayoutParams

LinearLayout.LayoutParams

XML Attributes

Attribute Name

Related Method

Description

android:layout_gravity

 

Standard gravity constant that a child supplies to its parent. 

android:layout_weight

 

 

 

 

 

 

 

ViewGroup.LayoutParams

ViewGroup.MarginLayoutParams

RelativeLayout.LayoutParams

 

XML Attributes

Attribute Name

Related Method

Description

android:layout_above

 

Positions the bottom edge of this view above the given anchor view ID. 

android:layout_alignBaseline

 

Positions the baseline of this view on the baseline of the given anchor view ID. 

android:layout_alignBottom

 

Makes the bottom edge of this view match the bottom edge of the given anchor view ID. 

android:layout_alignEnd

 

Makes the end edge of this view match the end edge of the given anchor view ID. 

android:layout_alignLeft

 

Makes the left edge of this view match the left edge of the given anchor view ID. 

android:layout_alignParentBottom

 

If true, makes the bottom edge of this view match the bottom edge of the parent. 

android:layout_alignParentEnd

 

If true, makes the end edge of this view match the end edge of the parent. 

android:layout_alignParentLeft

 

If true, makes the left edge of this view match the left edge of the parent. 

android:layout_alignParentRight

 

If true, makes the right edge of this view match the right edge of the parent. 

android:layout_alignParentStart

 

If true, makes the start edge of this view match the start edge of the parent. 

android:layout_alignParentTop

 

If true, makes the top edge of this view match the top edge of the parent. 

android:layout_alignRight

 

Makes the right edge of this view match the right edge of the given anchor view ID. 

android:layout_alignStart

 

Makes the start edge of this view match the start edge of the given anchor view ID. 

android:layout_alignTop

 

Makes the top edge of this view match the top edge of the given anchor view ID. 

android:layout_alignWithParentIfMissing

 

If set to true, the parent will be used as the anchor when the anchor cannot be be found for layout_toLeftOf, layout_toRightOf, etc. 

android:layout_below

 

Positions the top edge of this view below the given anchor view ID. 

android:layout_centerHorizontal

 

If true, centers this child horizontally within its parent. 

android:layout_centerInParent

 

If true, centers this child horizontally and vertically within its parent. 

android:layout_centerVertical

 

If true, centers this child vertically within its parent. 

android:layout_toEndOf

 

Positions the start edge of this view to the end of the given anchor view ID. 

android:layout_toLeftOf

 

Positions the right edge of this view to the left of the given anchor view ID. 

android:layout_toRightOf

 

Positions the left edge of this view to the right of the given anchor view ID. 

android:layout_toStartOf

 

Positions the end edge of this view to the start of the given anchor view ID. 

 

ViewGroup.LayoutParams

ViewGroup.MarginLayoutParams

FrameLayout.LayoutParams

XML Attributes

Attribute Name

Related Method

Description

android:layout_gravity

 

Standard gravity constant that a child supplies to its parent. 

 

 

View

 

XML Attributes

Attribute Name

Related Method

Description

android:accessibilityLiveRegion

setAccessibilityLiveRegion(int)

Indicates to accessibility services whether the user should be notified when this view changes. 

android:alpha

setAlpha(float)

alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). 

android:background

setBackgroundResource(int)

A drawable to use as the background. 

android:clickable

setClickable(boolean)

Defines whether this view reacts to click events. 

android:contentDescription

setContentDescription(CharSequence)

Defines text that briefly describes content of the view. 

android:drawingCacheQuality

setDrawingCacheQuality(int)

Defines the quality of translucent drawing caches. 

android:duplicateParentState

 

When this attribute is set to true, the view gets its drawable state (focused, pressed, etc.) from its direct parent rather than from itself. 

android:fadeScrollbars

setScrollbarFadingEnabled(boolean)

Defines whether to fade out scrollbars when they are not in use. 

android:fadingEdgeLength

getVerticalFadingEdgeLength()

Defines the length of the fading edges. 

android:filterTouchesWhenObscured

setFilterTouchesWhenObscured(boolean)

Specifies whether to filter touches when the view's window is obscured by another visible window. 

android:fitsSystemWindows

setFitsSystemWindows(boolean)

Boolean internal attribute to adjust view layout based on system windows such as the status bar. 

android:focusable

setFocusable(boolean)

Boolean that controls whether a view can take focus. 

android:focusableInTouchMode

setFocusableInTouchMode(boolean)

Boolean that controls whether a view can take focus while in touch mode. 

android:hapticFeedbackEnabled

setHapticFeedbackEnabled(boolean)

Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. 

android:id

setId(int)

Supply an identifier name for this view, to later retrieve it withView.findViewById() or Activity.findViewById()

android:importantForAccessibility

setImportantForAccessibility(int)

Controls how this View is important for accessibility which is if it fires accessibility events and if it is reported to accessibility services that query the screen. 

android:isScrollContainer

setScrollContainer(boolean)

Set this if the view will serve as a scrolling container, meaing that it can be resized to shrink its overall window so that there will be space for an input method. 

android:keepScreenOn

setKeepScreenOn(boolean)

Controls whether the view's window should keep the screen on while visible. 

android:layerType

setLayerType(int,Paint)

Specifies the type of layer backing this view. 

android:layoutDirection

setLayoutDirection(int)

Defines the direction of layout drawing. 

android:longClickable

setLongClickable(boolean)

Defines whether this view reacts to long click events. 

android:minHeight

setMinimumHeight(int)

Defines the minimum height of the view. 

android:minWidth

setMinimumWidth(int)

Defines the minimum width of the view. 

android:nextFocusDown

setNextFocusDownId(int)

Defines the next view to give focus to when the next focus isFOCUS_DOWN If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeExceptionwill result when the reference is accessed. 

android:nextFocusForward

setNextFocusForwardId(int)

Defines the next view to give focus to when the next focus isFOCUS_FORWARD If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeExceptionwill result when the reference is accessed. 

android:nextFocusLeft

setNextFocusLeftId(int)

Defines the next view to give focus to when the next focus isFOCUS_LEFT

android:nextFocusRight

setNextFocusRightId(int)

Defines the next view to give focus to when the next focus isFOCUS_RIGHT If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeExceptionwill result when the reference is accessed. 

android:nextFocusUp

setNextFocusUpId(int)

Defines the next view to give focus to when the next focus isFOCUS_UP If the reference refers to a view that does not exist or is part of a hierarchy that is invisible, a RuntimeException will result when the reference is accessed. 

android:onClick

 

Name of the method in this View's context to invoke when the view is clicked. 

android:padding

setPaddingRelative(int,int,int,int)

Sets the padding, in pixels, of all four edges. 

android:paddingBottom

setPaddingRelative(int,int,int,int)

Sets the padding, in pixels, of the bottom edge; see padding

android:paddingEnd

setPaddingRelative(int,int,int,int)

Sets the padding, in pixels, of the end edge; see padding

android:paddingLeft

setPadding(int,int,int,int)

Sets the padding, in pixels, of the left edge; see padding

android:paddingRight

setPadding(int,int,int,int)

Sets the padding, in pixels, of the right edge; see padding

android:paddingStart

setPaddingRelative(int,int,int,int)

Sets the padding, in pixels, of the start edge; see padding

android:paddingTop

setPaddingRelative(int,int,int,int)

Sets the padding, in pixels, of the top edge; see padding

android:requiresFadingEdge

setVerticalFadingEdgeEnabled(boolean)

Defines which edges should be faded on scrolling. 

android:rotation

setRotation(float)

rotation of the view, in degrees. 

android:rotationX

setRotationX(float)

rotation of the view around the x axis, in degrees. 

android:rotationY

setRotationY(float)

rotation of the view around the y axis, in degrees. 

android:saveEnabled

setSaveEnabled(boolean)

If unset, no state will be saved for this view when it is being frozen. 

android:scaleX

setScaleX(float)

scale of the view in the x direction. 

android:scaleY

setScaleY(float)

scale of the view in the y direction. 

android:scrollX

 

The initial horizontal scroll offset, in pixels. 

android:scrollY

 

The initial vertical scroll offset, in pixels. 

android:scrollbarAlwaysDrawHorizontalTrack

 

Defines whether the horizontal scrollbar track should always be drawn. 

android:scrollbarAlwaysDrawVerticalTrack

 

Defines whether the vertical scrollbar track should always be drawn. 

android:scrollbarDefaultDelayBeforeFade

setScrollBarDefaultDelayBeforeFade(int)

Defines the delay in milliseconds that a scrollbar waits before fade out. 

android:scrollbarFadeDuration

setScrollBarFadeDuration(int)

Defines the delay in milliseconds that a scrollbar takes to fade out. 

android:scrollbarSize

setScrollBarSize(int)

Sets the width of vertical scrollbars and height of horizontal scrollbars. 

android:scrollbarStyle

setScrollBarStyle(int)

Controls the scrollbar style and position. 

android:scrollbarThumbHorizontal

 

Defines the horizontal scrollbar thumb drawable. 

android:scrollbarThumbVertical

 

Defines the vertical scrollbar thumb drawable. 

android:scrollbarTrackHorizontal

 

Defines the horizontal scrollbar track drawable. 

android:scrollbarTrackVertical

 

Defines the vertical scrollbar track drawable. 

android:scrollbars

 

Defines which scrollbars should be displayed on scrolling or not. 

android:soundEffectsEnabled

setSoundEffectsEnabled(boolean)

Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching. 

android:tag

 

Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for withView.findViewWithTag()

android:textAlignment

setTextAlignment(int)

Defines the alignment of the text. 

android:textDirection

setTextDirection(int)

Defines the direction of the text. 

android:transformPivotX

setPivotX(float)

x location of the pivot point around which the view will rotate and scale. 

android:transformPivotY

setPivotY(float)

y location of the pivot point around which the view will rotate and scale. 

android:translationX

setTranslationX(float)

translation in x of the view. 

android:translationY

setTranslationY(float)

translation in y of the view. 

android:visibility

setVisibility(int)

Controls the initial visibility of the view. 

 

0 0