View屬性小結(jié)
待改進(jìn)
標(biāo)識類屬性
-
android:id:Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById(). [reference]:提供一個標(biāo)識符名稱給這個組件,后面可以通過:
View.findViewById()
或者Activity.findViewById()
來獲取這個組件。方法:
- setId(int)
android:tag:Supply a tag for this view containing a String, to be retrieved later with View.getTag() or searched for with View.findViewWithTag() . [string]:這個屬性和
android:id
的作用和用法一樣,api上建議使用android:id
原因是id更快而且支持編譯時類型的檢查(It is generally preferable to use IDs (through the android:id attribute) instead of tags because they are faster and allow for compile-time type checking.)android:contentDescription:Defines text that briefly describes content of the view. [string]:定義一個文本來暫時描述這個控件
位置類屬性
scrollX/Y:The initial vertical/horizontal scroll offset, in pixels. [dimension]:初始的垂直/水平 滾動偏移量,像素為單位
-
padding:Sets the padding, in pixels, of all four edges. [dimension]:設(shè)置四面的外邊距,以像素為單位,控件的大小是包括了padding的,padding可以覆蓋背景
方法
- setPaddingRelative(int,int,int,int)
-
paddingTop/Bottom/Left/Right/End/Start:Sets the padding, in pixels, of the left// edge; see padding. [dimension]
方法
- setPaddingRelative(int,int,int,int)
android:fitsSystemWindows:Boolean internal attribute to adjust view layout based on system windows such as the status bar. [boolean]:是否要更具系統(tǒng)的窗口的改變(比如是否有狀態(tài)欄)而改變控件的內(nèi)部屬性;
-
translationX/Y:translation in x/y of the view. [dimension]:改變位置?
方法
- setTranslation(float)
-
android:layoutDirection:Defines the direction of layout drawing. [enum]:定義控件的繪制方向
屬性值
- ltr:0,Left-to-Right
- rtl:1,Right-to-Left
- inherit:3,Inherit from parent
- locale:3,Locale
外觀類屬性
-
android:background:A drawable to use as the background. [color, reference]:將一個可繪制的東西作為背景
方法:
- setBackgroundResource(int)
-
android:visibility:Controls the initial visibility of the view. [enum]:設(shè)置控件舒適化是是否可見
屬性值
- visibile:0,Visible on screen; the default value.可見,默認(rèn)值
- invisibile:1,Not displayed, but taken into account during layout (space is left for it).不可見,但是占據(jù)地方
- gone,2,Completely hidden, as if the view had not been added.完全隱藏,控件不會添加到布局中。
方法
- setVisibility(int)
-
android:scrollbars:Defines which scrollbars should be displayed on scrolling or not. [flag]:定義哪個滾動條滾動(是可滾動還是顯示?)
- none:0x00000000,No scrollbar is displayed.
- horizontal:0x00000100,Displays horizontal scrollbar only.
- vertical:0x00000200,Displays vertical scrollbar only.
-
android:scrollbarStyle:Controls the scrollbar style and position. [enum]:控制滾動條的風(fēng)格和位置
- insideOverlay:0x0,Inside the padding and overlaid
- insideinset:0x01000000,Inside the padding and inset
- outsideOverlay:0x02000000,Edge of the view and overlaid
- outsideinset:0x03000000,Edge of the view and inset
方法
- setScrollBarStyle(int)
-
android:fadeScrollbars:Defines whether to fade out scrollbars when they are not in use. [boolean]:定義是否要做模糊處理對于沒有使用的滾動條
方法
- setScrollbarFadingEnable(boolean)
-
android:scrollbarFadeDuration:Defines the delay in milliseconds that a scrollbar takes to fade out. [integer]:設(shè)置滾動條fade out過程話費(fèi)的時間
方法
- setScrollBarFadeDuration(int)
-
android:scrollbarDefaultDelayBeforeFade:Defines the delay in milliseconds that a scrollbar waits before fade out. [integer]:設(shè)置滾動條fade out 延遲的時間
方法
- setScrollBarDefaultDelayBeforeFade(int)
-
android:scrollbarSize:Sets the width of vertical scrollbars and height of horizontal scrollbars. [dimension]:設(shè)置水平滾動條的高度或者垂直滾動條的寬度。
方法
- setScorllBarSize(int)
android:scrollbarTrackHorizontal/Vertical:Defines the horizontal/vertical scrollbar track drawable. [reference]:定義軌跡
-
android:requiresFadingEdge:Defines which edges should be faded on scrolling. [flag]:定義哪個邊緣應(yīng)該被模糊處理在滾動的時候
屬性值
- none:0x00000000,No edge is faded.
- horizontal:0x00001000,F(xiàn)ades horizontal edges only.
- vertical:0x00002000,F(xiàn)ades vertical edges only.
方法
- setVerticalFadingEdgeEnabled(boolean)
- setHorizontalFadingEdgeEnabled(boolean)
-
android:fadingEdgeLength:Defines the length of the fading edges. [dimension]:定義邊緣填充的長度
方法
- getVerticalFadingEdgeLength()
-
android:keepScreenOn:Controls whether the view's window should keep the screen on while visible. [boolean]:設(shè)置控件是否能夠保持屏幕常亮
方法
- setKeepScreenOn(boolean)
-
android:minHeight:Defines the minimum height of the view.:定義控件的最小高度
方法
- setMinimunHeight(int)
-
android:minWidth:Defines the minimum width of the view.:定義控件的最小寬度
方法
- setMinimunWidth(int)
-
android:alpha:alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). [float]:設(shè)置控件的透明度(值 0-1)
方法
- setAlpha(float)
-
android:rotation:rotation of the view, in degrees. [float]:設(shè)置控件的旋轉(zhuǎn)角度
方法
- serRotation(float)
-
android:rotationX/Y:rotation of the view around the x/y axis, in degrees. [float]:設(shè)置旋轉(zhuǎn)的中心
方法
- setRotationX(float)
- setRotationY(float)
-
android:scaleX/Y:scale of the view in the x/y direction. [float]:設(shè)置控件在某個方向上的大小
方法
- setScaleX(float)
-
textDirection:Defines the direction of the text. [integer, enum]
- inherit:0,Default
- firstStrong:1,
- anyRtl:2,
- ltr:3,
- rtl:4,
- locale:5,
- firstStrongLtr:6,
- firstStrongRtl:7,
-
android:textAlignment:Defines the alignment of the text. [integer, enum]:定義控件中文本的對齊方式
- inherit:0,Default
- vertical:1,
- textStart:2,
- textEnd:3,
- center:4,
- viewStart:5,
- viewEnd:6,
方法
- setTextAlignment(int)
焦點(diǎn)、動作
-
android:focusable:Boolean that controls whether a view can take focus. [boolean]:設(shè)置控件能否接收焦點(diǎn)
方法
- setFocusable(boolean)
-
focusableInTouchMode:Boolean that controls whether a view can take focus while in touch mode. [boolean]:設(shè)置控件能否能夠獲得焦點(diǎn)在觸摸模式下
方法
- setFocusableInTouchMode(boolean)
-
android:nextFocusLeft:Defines the next view to give focus to when the next focus is FOCUS_LEFT. [reference]:定義當(dāng)按下左的時候下一個獲得焦點(diǎn)的控件
方法
- setNextFocusLeftId(int);
-
android:nextFocusForward/Right/Up/Bottom:Defines the next view to give focus to when the next focus is FOCUS_RIGHT If the reference refers to a view that does not exizst or is part of a hierarchy that is invisible, a java.lang.RuntimeException will result when the reference is accessed. [reference]
方法
- setNextFocusRightId(int)
- setNextFocusUpId(int)
- setNextFocusForward(int)
- setNextFocusBottom(int)
-
android:clickable:Defines whether this view reacts to click events. [boolean]:定義這個控件能否觸發(fā)點(diǎn)擊事件
方法
- setClickable(boolean)
-
android:longClickable:Defines whether this view reacts to long click events. [boolean]:定義控件是否可以反饋長點(diǎn)擊事件
方法
- setLongClickable(boolean)
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. [boolean]:控制控件的狀態(tài)(焦點(diǎn),按壓)是否由父控件決定
android:onClick:Name of the method in this View's context to invoke when the view is clicked. [string]:當(dāng)控件被點(diǎn)擊的時候能否被環(huán)境所調(diào)用,F(xiàn)or instance, if you specify
android:onClick="sayHello"
, you must declare apublic void sayHello(View v)
method of your context (typically, your Activity).-
android:longClickable:Defines whether this view reacts to long click events. [boolean]:定義這個控件是否可以有長按的事件反饋
方法
- setLongClickable(boolean)
動畫
性能類屬性
scrollbarAlwaysDrawHorizontal(Vertical)Track:Defines whether the horizontal(vertical) scrollbar track should always be drawn. [boolean]:定義水平/垂直 滾動條是否要一直被繪制
-
android:saveEnabled:If unset, no state will be saved for this view when it is being frozen. [boolean]:設(shè)置控件的狀態(tài)是否能被保存。
方法
- setSaveEnable(boolean)
-
drawingCacheQuality:Defines the quality of translucent drawing caches. [enum]:定義透明繪制的緩沖特性
- auto:0,Lets the framework decide what quality level should be used for the drawing cache.(默認(rèn)值)
- low:1,Low quality. When set to low quality, the drawing cache uses a lower color depth, thus losing precision in rendering gradients, but uses less memory.
- high:2,High quality. When set to high quality, the drawing cache uses a higher color depth but uses more memory.
方法
- setDrawingCacheQuality(int)
-
android:layerType:Specifies the type of layer backing this view. [enum] (硬件加速?)
- none:0,Don't use a layer.
- software:1,Use a software layer. Refer to
setLayerType(int, android.graphics.Paint)
for more information. - hardware:2,Use a hardware layer. Refer to
setLayerType(int, android.graphics.Paint)
for more information.
方法
- setLayerType(int,Paint)
功能屬性
-
android:soundEffectsEnabled:Boolean that controls whether a view should have sound effects enabled for events such as clicking and touching. [boolean]:設(shè)置控件在點(diǎn)擊和觸摸的時候是否有聲音的反饋
方法
- setSoundEffectsEnabled(boolean)
-
android:hapticFeedbackEnabled:Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. [boolean] :定義控件是否有haptic feedback對于一些事件
方法
- setHapticFeedbackEnabled(boolean)
-
android:filterTouchesWhenObscured:Specifies whether to filter touches when the view's window is obscured by another visible window. [boolean]:設(shè)置當(dāng)控件被其他控件覆蓋的時候能否反饋觸碰操作
方法
- setFilterTouchesWhenObscured(boolean)
-
android:accessibilityLiveRegion:Indicates to accessibility services whether the user should be notified when this view changes. [integer, enum]:表明當(dāng)控件改變的時候是否要讓用戶知道
屬性值
- none:0
- polite:1
- assertive:2
方法
- setAccessibilityLiveRegion(int)