文档库 最新最全的文档下载
当前位置:文档库 › 常用的基本控件

常用的基本控件

FrameLayout-帧布局
帧布局中的每一个组件都代表一个画面
默认以屏幕左上角作为(0.0)坐标,按组件定义的先后顺序依次逐屏显示。后面出现的会覆盖前面的画面。
用该布局可以实现动画效果。
FrameLayout的一个子类-TabHost很常用,可以实现导航界面
android:padding设置控件里面内容距离控件边框的距离
android:visibility=“visible”图片可见
android:visibility=“invisible”不可见但占用位置
android:visibility=“gone”不可见不占用位置(相当于去掉图片)
Absolutelayout-绝对布局
Absolutelayout又叫坐标布局,可以指定子元素的绝对位置
这种布局简单直接,直观性强
使用android:layout_x属性确定x坐标以左上角为顶点
使用android:layout_y属性确定y坐标以左上角为顶点
不设置layout_x和layout_y那么默认为0出现在左上角
由于手机屏幕尺寸差别比较大,使用绝对定位的适应性会比较差,不推荐使用
320x480 1px=1dp


三、常用的基本控件
1、与文本有关:Textview、EidtText、CheckedTextView等

Textview:
android:textColor=""设置文本颜色
android:backGround=“”设置背景色
android:textStyle=“bold”设置文本粗体
android:paddingLeft=“”设置文字距离TextView左边框的距离
android:autoLink=“web(email)”设置超链接(网址、邮箱)
android:autoLink=“phone”设置超链接(打电话)
android:textAppearance“@android:----”设置字体
android:singleline=“true”设置文本不换行
android:layout_gravicty=“”控件居于父窗体的位置
android:layout_marginTop=“100dp”设置距离父窗体顶部距离

EidtText:
android:hint="XXXXXXXX"设置编辑框内提示信息
android:lines=“10”设置编辑框的行数为10行
android:gravicty=“0dp”设置编辑框内的光标位于顶端,从顶端输入
android:password=“true”设置密码
android:phoneNumber=“true”设置文本只能输入数字
android:backGround=“@xxxxx/xxxxxx”设置输入框背景
android:paddingLeft=“”设置文字距离EidtText左边框的距离
TextView phoneNumber=(TextView)findViewById(https://www.wendangku.net/doc/3f2902758.html,_phoneNumber);
Toast.makeText(this,name1,1).show());显示文本1长显示,0短显示
tv_phoneNumber.setOnClickListener(new OnClickListener)

2、与图片有关:imageView、ImageButton(效率高但不能加文字)
ImageButton继承自ImageView,他们都是显示图片

imageView:
android:scr=“@drawable/xxxx”加入图片,图片多大显示多大
android:background=“@drawable/xxx”加入图片,背景多大,图片显示多大
android:scaleType=“matrix或fitxy”缩放类型(matrix矩阵)(fitxy)X,Y轴比例缩放(fitcenter居于中间开始缩放不变形)(center居于控件正中间不缩放)(centerCrop显示图片中间部分)(centerinsid内嵌效

果)
ImageButton:具有图片的按钮

3、与用户点击有关:Button、checkbox、radioButton、ToggleButton等后3者都是Button的子孙类、这4者都是textview的子孙类

Button:
android:text=""设置文本
android:textColor=""设置文本颜色
android:clickable=“false”按钮不点击
android:focusable=“true”获得焦点
android:visibility=“visible”按钮可见
android:visibility=“invisible”不可见但占用位置
android:visibility=“gone”不可见不占用位置
android:background=“@xxx/xxx”添加背景图片,图片可根据按钮大小变化

高级控件
1、AdapterView与Adapter
AdapterView即Adapter(适配器)控件、其内容通常是一个包含多项相同格式资源的列表,每次只显示其中一项。
需要先把多项内容放入一个列表,然后将这个列表加载到Adapter控件中。
这个存放Adapter控件的内容的列表,在Android被称为Adapter(适配器)。














相关文档
相关文档 最新文档