您的位置:首页 > 移动开发 > Android开发

android xml属性总结

2016-11-02 10:19 381 查看
View类的 XML 属性相关方法及说明
ViewGroupLayoutParams 支持的 XML 属性
ViewGroupMarginLayoutParams 支持的 XML 属性


View类的 XML 属性、相关方法及说明

Android 推荐用 XML 布局文件来定义用户界面,而不是使用 Java 代码来开发用户界面,因此所有组件都提供了两种方式来控制组件的行为。 
1.在XML 布局文件中通过XML 属性进行控制。 
2.在Java程序代码中通过调用方法进行控制。 

对于View 类而言,它是所有UI组件的基类,因此它包含的XML 属性和方法是所有组件都可使用的。
XML 属性相关方法说 明
android:alphasetAlpha(float)设置该组件的透明度
android:backgroundsetBackgroundResource(int)设置该组件的背景颜色
android:clickablesetClickable(boolean)设置该组件是否可以激发单击事件
android:contentDescriptionsetContentDescription(CharSequence)设置该组件的主要描述信息
android:drawingCacheQualitysetDrawingCacheQuality(int)设置该组件所使用的绘制缓存的质量
android:elevationsetElevation(float)设置该组件“浮”起来的高度,通过设置该属性可以让该组件呈现3D效果
android:fadeScrollbarssetScrollbarFadingEnabled(boolean)当不使用该组件的滚动条时,是否淡出显示滚动条
android:fadingEdgesetVerticalFadingEdgeEnabled(boolean)设置滚动该组件时组件边界是否使用淡出效果
android:fadingEdgeLengthgetVerticalFadingEdgeLength()设置淡出边界的长度
android:focusablesetFocusable(boolean)设置组件是否可以得到焦点
android:focusableInTouchModesetFocusableInTouchMode(boolean)设置该组件在触摸模式下是否可以得到焦点
android:idsetId(int)设置该组件的唯一标识。Java代码中可以通过findViewById来获取它
android:isScrollContainersetScrollContainer(boolean)设置该组件是否作为可滚动容器使用
android:keepScreenOnsetKeepScreenOn(boolean)设置该组件是否会强制手机屏幕一直打开
android:longClickablesetLongClickable(boolean)设置该组件是否可以响应长单击事件
android:minHeightsetMinimumHeight(int)设置该组件的最小高度
android:minWidthsetMinimumWidtht(int)设置该组件的最小宽度
android:nextFocusDownsetNextFocusDownId(int)设置焦点在该组件上,且按向下键时获得焦点的组件ID
android:nextFocusLeftsetNextFocusLeftId(int)设置焦点在该组件上,且按向左键时获得焦点的组件ID
android:nextFocusRightsetNextFocusRightId(int)设置焦点在该组件上,且按向右键时获得焦点的组件ID
android:nextFocusUpsetNextFocusUpId(int)设置焦点在该组件上,且按向上键时获得焦点的组件ID
android:onClick 为该组件的单击事件绑定监听器
android:paddingsetPadding(int,int,int,int)在组件的四边设置填充区域
android:paddingLeftsetPadding(int,int,int,int)在组件的左边设置填充区域
android:paddingTopsetPadding(int,int,int,int)在组件的上边设置填充区域
android:paddingRightsetPadding(int,int,int,int)在组件的右边设置填充区域
android:paddingBottomsetPadding(int,int,int,int)在组件的下边设置填充区域
android:rotationsetRotation(float)设置该组件旋转的角度
android:rotationXsetRotationX(float)设置该组件绕X轴旋转的角度
android:rotationYsetRotationY(float)设置该组件绕Y轴旋转的角度
android:saveEnabledsetSaveEnabled(boolean)如果设置为false,那当该组件被冻结时不会保存它的状态
android:scaleXsetScaleX(float)设置该组件在水平方向的缩放比
android:scaleYsetScaleY(float)设置该组件在垂直方向的缩放比
android:scrollX 该组件初始化后的水平滚动偏移
android:scrollY 该组件初始化后的垂直滚动偏移
android:scrollbarAlwaysDrawHorizontalTrack 设置该组件是否总是显示水平滚动条的轨迹
android:scrollbarAlwaysDrawVerticalTrack 设置该组件是否总是显示垂直滚动条的轨迹
android:scrollbarDefaultDelayBeforeFadesetScrollbarDefaultDelayBeforeFade(int)设置滚动条在淡出隐藏之前延迟多少毫秒
android:scrollbarFadeDurationsetScrollbarFadeDuration(int)设置滚动条淡出隐藏过程需要多少秒
android:scrollbarSizesetScrollbarSize(int)设置垂直滚动条的宽度和水平滚动条的高度
android:scrollbarStylesetScrollbarStyle(int)设置滚动条的风格和位置。该属性支持如下属性:

insideOverlay

insideInset

OutsideOverlay

OutsideInset
android:scrollbarThumbHorizontal 设置该组件的水平滚动条的滑块对应的Drawable对象
android:scrollbarThumbVertical 设置该组件的垂直滚动条的滑块对应的Drawable对象
android:scrollbarTrackHorizontal 设置该组件的水平滚动条的轨道对应的Drawable对象
android:scrollbarTrackVertical 设置该组件的垂直滚动条的轨道对应的Drawable对象
android:scrollbars 定义该组件滚动时显示几个滚动条,该属性支持如下属性值。

none:不显示滚动条

horizont:显示水平滚动条

vertical:显示垂直滚动条
android:soundEffectsEnabledsetSoundEffectsEnabled(boolean)设置该组件被单击时是否使用音效
android:tag 为该组件设置一个字符串类型的tag值。接下来可通过View的getTag()获取该字符串,或通过findViewWithTag()查找该组件
android:transformPivotXsetPivotX(float)设置该组件旋转时旋转中心的X坐标
android:transformPivotYsetPivotY(float)设置该组件旋转时旋转中心的Y坐标
android:translationXsetTranslationX(float)设置该组件在X方向上位移
android:translationYsetTranslationY(float)设置该组件在Y方向上位移
android:translationZsetTranslationZ(float)设置该组件在Z方向上(垂直屏幕方向)上的位移
android:visibilitysetVisibility(int)设置该组件是否可见


ViewGroup.LayoutParams 支持的 XML 属性

ViewGroup 容器控制其子组件的分布依赖于 ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams 两个内部类。这两个内部类中都提供了一些 XML 属性,ViewGroup 容器中的子组件可以指定这些 XML 属性。
XML 属性说明
android:layout_height指定该子组件的布局高度
android:layout_width指定该子组件的布局宽度
android:layout_height、android:layout_width 两个属性支持如下3个属性值。 

1.fill_parent: 指定子组件的高度、宽度与父容器组件的高度、宽度相同(实际上还要减去填充的空白距离)。 

2.match_parent:该属性值与 fill_parent 完全相同,而且从Android 2.2 开始就推荐使用这个属性值来代替fill_parent。 

3.wrap_content:指定子组件的大小恰好能包裹它的内容即可。


ViewGroup.MarginLayoutParams 支持的 XML 属性

ViewGroup.MarginLayoutParams 用于控制子组件周围的页边距(Margin,也就是组件四周的留白),它支持的 XML 属性如下表。
XML 属性相关方法说 明
android:layout_marginBottomsetMargins(int,int,int,int)指定该子组件下边的页边距
android:layout_marginLeftsetMargins(int,int,int,int)指定该子组件左边的页边距
android:layout_marginRightsetMargins(int,int,int,int)指定该子组件右边的页边距
android:layout_marginTopsetMargins(int,int,int,int)指定该子组件上边的页边距
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: