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

Android笔记(六) Android中的组件

2015-08-14 14:55 549 查看
一个软件可以吸引到用户,除了优秀的功能可以解决用户的问题之外,良好的用户界面也并不可少。一个软件的功能不管多么优秀,但是没有提供友好的界面来让用户操作,将很难吸引到最终用户。

Android提供了大量的UI组件,开发者按照一定规律把这些UI组件组合在一起,形成一个优秀的图形用户界面,再通过Android提供的事件响应机制,让这些组件可以响应用户的点击、拖动,最终完成用户的交互操作。

Android应用的绝大部分UI组件都放在android.widget包及其子包、android.view包机器子包中并且都继承了View类。

View还有一个子类ViewGroup,ViewGroup通常作为其他组件的容器来使用,ViewGroup除了可以放其他组件,也可以放另外一个ViewGroup,所以Android的所有组件都是建立在View、ViewGroup基础上的。

View的直接子类、间接子类包含常见的Button、CheckBox、EditText、TextView等组件。

GroupView的子类通常用来作为容器,例如各种布局管理器

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

XML 属性

相关方法

说明

android:alpha

setAlpha(float)

设置该组件的透明度

android:background

setBackgroundResource(int)

设置该组件的背景颜色

android:clickable

setClickable(boolean)

设置该组件是否可以激发单击事件

android:contentDescription

setContentDescription(CharSequence)

设置该组件的主要描述信息

android:drawingCacheQuality

setDrawingCacheQuality(iint)

设置该组件所使用的绘制缓存的质量

android:fadeScrollbars

setScrollbarFadingEnabled(boolean)

当不使用该组件的滚动条时,是否淡出显示滚动条

android:fadingEdge

setVerticalFadingEdgeEnabled(boolean)

设置滚动该组件时组件边界是否使用淡出效果

android:fadingEdgeLength

getVerticalFadingEdgeLength()

设置淡出边界的长度

android:focusable

setFocusable(boolean)

设置组件是否可以得到焦点

android:focusableInTouchMode

setFocusableInTouchMode(boolean)

设置该组件在触摸模式下是否可以得到焦点

android:id

setId(int)

设置该组件的唯一标识。Java 代码中可以通过 findViewById 来获取它

android:isScrollContainer

setScrollContainer(boolean)

设置该组件是否作为可滚动容器使用

android:keepScreenOn

setKeepScreenOn(boolean)

设置该组件是否会强制手机屏幕一直打开

android:longClickable

setLongClickable(boolean)

设置该组件是否可以响应长单击事件

android:minHeight

setMinimumHeight(int)

设置该组件的最小高度

android:minWidth

setMinimumWidtht(int)

设置该组件的最小宽度

android:nextFocusDown

SetNextFocusDownId(int)

设置焦点在该组件上,且按向下键时获得焦点的组件 ID

android:nextFocusLeft

setNextFocusLeftId(int)

设置焦点在该组件上,且按向左键时获得焦点的组件 ID

android:nextFocusRight

setNextFocusRightId(int)

设置焦点在该组件上,且按向右键时获得焦点的组件 ID

android:nextFocusUp

setNextFocusUpId(int)

设置焦点在该组件上,且按向上键时获得焦点的组件 ID

android:onClick

为该组件的单击事件绑定监听器

android:padding

setPadding(int,int,int,int)

在组件的四边设置填充区域

android:paddingLeft

setPadding(int,int,int,int)

在组件的左边设置填充区域

android:paddingTop

setPadding(int,int,int,int)

在组件的上边设置填充区域

android:paddingRight

setPadding(int,int,int,int)

在组件的右边设置填充区域

android:paddingBottom

setPadding(int,int,int,int)

在组件的下边设置填充区域

android:rotation

setRotation(float)

设置该组件旋转的角度

android:rotationX

setRotationX(float)

设置该组件绕X 轴旋转的角度

android:rotationY

setRotationY(float)

设置该组件绕Y 轴旋转的角度

android:saveEnabled

setSaveEnabled(boolean)

如果设置为false ,那当该组件被冻结时不会保存它的状态

android:scaleX

setScaleX(float)

设置该组件在水平方向的缩放比

android:scaleY

setScaleY(float)

设置该组件在垂直方向的缩放比

android:scrollX

该组件初始化后的水平滚动偏移

android:scrollY

该组件初始化后的垂直滚动偏移

android:scrollbarAlwaysDrawHorizontalTrack

设置该组件是否总是显示水平滚动条的轨迹

android:scrollbarAlwaysDrawVerticalTrack

设置该组件是否总是显示垂直滚动条的轨迹

android:scrollbarDefaultDelayBeforeFade

setScrollbarDefaultDelayBeforeFade(int)

设置滚动条在淡出隐藏之前延迟多少毫秒

android:scrollbarFadeDuration

setScrollbarFadeDuration(int)

设置滚动条淡出隐藏过程需要多少秒

android:scrollbarSize

setScrollbarSize(int)

设置垂直滚动条的宽度和水平滚动条的高度

android:scrollbarStyle

setScrollbarStyle(int)

设置滚动条的风格和位置。该属性支持如下属性:

insideOverlay

insideInset

OutsideOverlay

OutsideInset

android:scrollbarThumbHorizontal

设置该组件的水平滚动条的滑块对应的Drawable 对象

android:scrollbarThumbVertical

设置该组件的垂直滚动条的滑块对应的Drawable 对象

android:scrollbarTrackHorizontal

设置该组件的水平滚动条的轨道对应的Drawable 对象

android:scrollbarTrackVertical

设置该组件的垂直滚动条的轨道对应的Drawable 对象

android:scrollbars

定义该组件滚动时显示几个滚动条,该属性支持如下属性值。

none :不显示滚动条

horizont :显示水平滚动条

vertical :显示垂直滚动条

android:soundEffectsEnabled

setSoundEffectsEnabled(boolean)

设置该组件被单击时是否使用音效

android:tag

为该组件设置一个字符串类型的tag 值。接下来可通过 View 的 getTag() 获取该字符串,或通过 findViewWithTag() 查找该组件

android:transformPivotX

setPivotX(float)

设置该组件旋转时旋转中心的 X 坐标

android:transformPivotY

setPivotY(float)

设置该组件旋转时旋转中心的 Y 坐标

android:translationX

setTranslationX(float)

设置该组件在X 方向上位移

android:translationY

setTranslationY(float)

设置该组件在Y 方向上位移

android:

setVisibility(int)

设置该组件是否可见

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐