View属性小结
待改进
标识类属性
-
android:id:Supply an identifier name for this view, to later retrieve it with View.findViewById() or Activity.findViewById(). [reference]:提供一个标识符名称给这个组件,后面可以通过:
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]:设置四面的外边距,以像素为单位,控件的大小是包括了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]:是否要更具系统的窗口的改变(比如是否有状态栏)而改变控件的内部属性;
-
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]:设置控件舒适化是是否可见
属性值
- visibile:0,Visible on screen; the default value.可见,默认值
- invisibile:1,Not displayed, but taken into account during layout (space is left for it).不可见,但是占据地方
- 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]:控制滚动条的风格和位置
- 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]:设置滚动条fade out过程话费的时间
方法
- setScrollBarFadeDuration(int)
-
android:scrollbarDefaultDelayBeforeFade:Defines the delay in milliseconds that a scrollbar waits before fade out. [integer]:设置滚动条fade out 延迟的时间
方法
- setScrollBarDefaultDelayBeforeFade(int)
-
android:scrollbarSize:Sets the width of vertical scrollbars and height of horizontal scrollbars. [dimension]:设置水平滚动条的高度或者垂直滚动条的宽度。
方法
- setScorllBarSize(int)
android:scrollbarTrackHorizontal/Vertical:Defines the horizontal/vertical scrollbar track drawable. [reference]:定义轨迹
-
android:requiresFadingEdge:Defines which edges should be faded on scrolling. [flag]:定义哪个边缘应该被模糊处理在滚动的时候
属性值
- none:0x00000000,No edge is faded.
- horizontal:0x00001000,Fades horizontal edges only.
- vertical:0x00002000,Fades 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]:设置控件是否能够保持屏幕常亮
方法
- 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]:设置控件的透明度(值 0-1)
方法
- setAlpha(float)
-
android:rotation:rotation of the view, in degrees. [float]:设置控件的旋转角度
方法
- serRotation(float)
-
android:rotationX/Y:rotation of the view around the x/y axis, in degrees. [float]:设置旋转的中心
方法
- setRotationX(float)
- setRotationY(float)
-
android:scaleX/Y:scale of the view in the x/y direction. [float]:设置控件在某个方向上的大小
方法
- 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)
焦点、动作
-
android:focusable:Boolean that controls whether a view can take focus. [boolean]:设置控件能否接收焦点
方法
- setFocusable(boolean)
-
focusableInTouchMode:Boolean that controls whether a view can take focus while in touch mode. [boolean]:设置控件能否能够获得焦点在触摸模式下
方法
- setFocusableInTouchMode(boolean)
-
android:nextFocusLeft:Defines the next view to give focus to when the next focus is FOCUS_LEFT. [reference]:定义当按下左的时候下一个获得焦点的控件
方法
- 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]:定义这个控件能否触发点击事件
方法
- setClickable(boolean)
-
android:longClickable:Defines whether this view reacts to long click events. [boolean]:定义控件是否可以反馈长点击事件
方法
- 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]:控制控件的状态(焦点,按压)是否由父控件决定
android:onClick:Name of the method in this View's context to invoke when the view is clicked. [string]:当控件被点击的时候能否被环境所调用,For 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]:设置控件的状态是否能被保存。
方法
- 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.(默认值)
- 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]:设置控件在点击和触摸的时候是否有声音的反馈
方法
- 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]:设置当控件被其他控件覆盖的时候能否反馈触碰操作
方法
- setFilterTouchesWhenObscured(boolean)
-
android:accessibilityLiveRegion:Indicates to accessibility services whether the user should be notified when this view changes. [integer, enum]:表明当控件改变的时候是否要让用户知道
属性值
- none:0
- polite:1
- assertive:2
方法
- setAccessibilityLiveRegion(int)