View屬性小結(jié)

View屬性小結(jié)

待改進(jìn)

標(biāo)識類屬性

  1. 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)
  2. 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.)

  3. android:contentDescription:Defines text that briefly describes content of the view. [string]:定義一個文本來暫時描述這個控件

位置類屬性

  1. scrollX/Y:The initial vertical/horizontal scroll offset, in pixels. [dimension]:初始的垂直/水平 滾動偏移量,像素為單位

  2. padding:Sets the padding, in pixels, of all four edges. [dimension]:設(shè)置四面的外邊距,以像素為單位,控件的大小是包括了padding的,padding可以覆蓋背景

    方法

    • setPaddingRelative(int,int,int,int)
  3. paddingTop/Bottom/Left/Right/End/Start:Sets the padding, in pixels, of the left// edge; see padding. [dimension]

    方法

    • setPaddingRelative(int,int,int,int)
  4. 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)部屬性;

  5. translationX/Y:translation in x/y of the view. [dimension]:改變位置?

    方法

    • setTranslation(float)
  6. 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

外觀類屬性

  1. android:background:A drawable to use as the background. [color, reference]:將一個可繪制的東西作為背景

    方法:

    • setBackgroundResource(int)
  2. android:visibility:Controls the initial visibility of the view. [enum]:設(shè)置控件舒適化是是否可見

    屬性值

    1. visibile:0,Visible on screen; the default value.可見,默認(rèn)值
    2. invisibile:1,Not displayed, but taken into account during layout (space is left for it).不可見,但是占據(jù)地方
    3. gone,2,Completely hidden, as if the view had not been added.完全隱藏,控件不會添加到布局中。

    方法

    • setVisibility(int)
  3. android:scrollbars:Defines which scrollbars should be displayed on scrolling or not. [flag]:定義哪個滾動條滾動(是可滾動還是顯示?)

    1. none:0x00000000,No scrollbar is displayed.
    2. horizontal:0x00000100,Displays horizontal scrollbar only.
    3. vertical:0x00000200,Displays vertical scrollbar only.
  4. android:scrollbarStyle:Controls the scrollbar style and position. [enum]:控制滾動條的風(fēng)格和位置

    1. insideOverlay:0x0,Inside the padding and overlaid
    2. insideinset:0x01000000,Inside the padding and inset
    3. outsideOverlay:0x02000000,Edge of the view and overlaid
    4. outsideinset:0x03000000,Edge of the view and inset

    方法

    • setScrollBarStyle(int)
  5. android:fadeScrollbars:Defines whether to fade out scrollbars when they are not in use. [boolean]:定義是否要做模糊處理對于沒有使用的滾動條

    方法

    • setScrollbarFadingEnable(boolean)
  6. android:scrollbarFadeDuration:Defines the delay in milliseconds that a scrollbar takes to fade out. [integer]:設(shè)置滾動條fade out過程話費(fèi)的時間

    方法

    • setScrollBarFadeDuration(int)
  7. android:scrollbarDefaultDelayBeforeFade:Defines the delay in milliseconds that a scrollbar waits before fade out. [integer]:設(shè)置滾動條fade out 延遲的時間

    方法

    • setScrollBarDefaultDelayBeforeFade(int)
  8. android:scrollbarSize:Sets the width of vertical scrollbars and height of horizontal scrollbars. [dimension]:設(shè)置水平滾動條的高度或者垂直滾動條的寬度。

    方法

    • setScorllBarSize(int)
  9. android:scrollbarTrackHorizontal/Vertical:Defines the horizontal/vertical scrollbar track drawable. [reference]:定義軌跡

  10. 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)
  11. android:fadingEdgeLength:Defines the length of the fading edges. [dimension]:定義邊緣填充的長度

    方法

    • getVerticalFadingEdgeLength()
  12. android:keepScreenOn:Controls whether the view's window should keep the screen on while visible. [boolean]:設(shè)置控件是否能夠保持屏幕常亮

    方法

    • setKeepScreenOn(boolean)
  13. android:minHeight:Defines the minimum height of the view.:定義控件的最小高度

    方法

    • setMinimunHeight(int)
  14. android:minWidth:Defines the minimum width of the view.:定義控件的最小寬度

    方法

    • setMinimunWidth(int)
  15. android:alpha:alpha property of the view, as a value between 0 (completely transparent) and 1 (completely opaque). [float]:設(shè)置控件的透明度(值 0-1)

    方法

    • setAlpha(float)
  16. android:rotation:rotation of the view, in degrees. [float]:設(shè)置控件的旋轉(zhuǎn)角度

    方法

    • serRotation(float)
  17. android:rotationX/Y:rotation of the view around the x/y axis, in degrees. [float]:設(shè)置旋轉(zhuǎn)的中心

    方法

    • setRotationX(float)
    • setRotationY(float)
  18. android:scaleX/Y:scale of the view in the x/y direction. [float]:設(shè)置控件在某個方向上的大小

    方法

    • setScaleX(float)
  19. textDirection:Defines the direction of the text. [integer, enum]

    1. inherit:0,Default
    2. firstStrong:1,
    3. anyRtl:2,
    4. ltr:3,
    5. rtl:4,
    6. locale:5,
    7. firstStrongLtr:6,
    8. firstStrongRtl:7,
  20. android:textAlignment:Defines the alignment of the text. [integer, enum]:定義控件中文本的對齊方式

    1. inherit:0,Default
    2. vertical:1,
    3. textStart:2,
    4. textEnd:3,
    5. center:4,
    6. viewStart:5,
    7. viewEnd:6,

    方法

    • setTextAlignment(int)
焦點(diǎn)、動作
  1. android:focusable:Boolean that controls whether a view can take focus. [boolean]:設(shè)置控件能否接收焦點(diǎn)

    方法

    • setFocusable(boolean)
  2. focusableInTouchMode:Boolean that controls whether a view can take focus while in touch mode. [boolean]:設(shè)置控件能否能夠獲得焦點(diǎn)在觸摸模式下

    方法

    • setFocusableInTouchMode(boolean)
  3. android:nextFocusLeft:Defines the next view to give focus to when the next focus is FOCUS_LEFT. [reference]:定義當(dāng)按下左的時候下一個獲得焦點(diǎn)的控件

    方法

    • setNextFocusLeftId(int);
  4. 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)
  5. android:clickable:Defines whether this view reacts to click events. [boolean]:定義這個控件能否觸發(fā)點(diǎn)擊事件

    方法

    • setClickable(boolean)
  6. android:longClickable:Defines whether this view reacts to long click events. [boolean]:定義控件是否可以反饋長點(diǎn)擊事件

    方法

    • setLongClickable(boolean)
  7. 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),按壓)是否由父控件決定

  8. 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 a public void sayHello(View v) method of your context (typically, your Activity).

  9. android:longClickable:Defines whether this view reacts to long click events. [boolean]:定義這個控件是否可以有長按的事件反饋

    方法

    • setLongClickable(boolean)
動畫

性能類屬性

  1. scrollbarAlwaysDrawHorizontal(Vertical)Track:Defines whether the horizontal(vertical) scrollbar track should always be drawn. [boolean]:定義水平/垂直 滾動條是否要一直被繪制

  2. android:saveEnabled:If unset, no state will be saved for this view when it is being frozen. [boolean]:設(shè)置控件的狀態(tài)是否能被保存。

    方法

    • setSaveEnable(boolean)
  3. drawingCacheQuality:Defines the quality of translucent drawing caches. [enum]:定義透明繪制的緩沖特性

    1. auto:0,Lets the framework decide what quality level should be used for the drawing cache.(默認(rèn)值)
    2. 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.
    3. high:2,High quality. When set to high quality, the drawing cache uses a higher color depth but uses more memory.

    方法

    • setDrawingCacheQuality(int)
  4. android:layerType:Specifies the type of layer backing this view. [enum] (硬件加速?)

    1. none:0,Don't use a layer.
    2. software:1,Use a software layer. Refer to setLayerType(int, android.graphics.Paint) for more information.
    3. hardware:2,Use a hardware layer. Refer to setLayerType(int, android.graphics.Paint) for more information.

    方法

    • setLayerType(int,Paint)

功能屬性

  1. 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)
  2. android:hapticFeedbackEnabled:Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. [boolean] :定義控件是否有haptic feedback對于一些事件

    方法

    • setHapticFeedbackEnabled(boolean)
  3. android:filterTouchesWhenObscured:Specifies whether to filter touches when the view's window is obscured by another visible window. [boolean]:設(shè)置當(dāng)控件被其他控件覆蓋的時候能否反饋觸碰操作

    方法

    • setFilterTouchesWhenObscured(boolean)
  4. 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)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,813評論 25 708
  • 今天早上五點(diǎn)多目送我媽出門去玩,想著為了下午也得養(yǎng)養(yǎng)精神于是又睡了一會兒,結(jié)果做了個夢,起來之后就開始焦慮,先是覺...
    Veronica閱讀 311評論 4 0
  • 草原之上 文/鄒航 站在草原,我試圖調(diào)整 自己的語言和姿態(tài) 從而擁抱大風(fēng)的胸懷 這是生病的夜晚,這是凍傷的草原 原...
    鄒航閱讀 245評論 0 1
  • 小和尚下山的時候,老和尚給了他一件寶物,那是一個可以收盡天下妖怪的紫金缽。山下的世界紛繁復(fù)雜,充滿了危險。山林里的...
    懶蟲小獅子閱讀 263評論 0 0