Android常用控件
来源:互联网 发布:淘宝哪家情侣装好看 编辑:程序博客网 时间:2024/06/14 19:03
Android基本布局和常用控件的日常使用
1.ScrollView
这个控件的使用一般是为了是界面可以有滚动条,可以为垂直方向的滚动,需要注意的是这个控件只能放在一个界面的最外层,并且这个控件内只能放一个布局文件。
2.LinearLayout
这个控件使用时需要注意它的方向是需要水平的还是需要垂直的。
3.ImageView
<ImageView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" //android:src = "@drawable/图片名称" android:src="@drawable/selector_position" android:visibility="visible" />
这个控件使用时需要注意的是图片的切换:
可以设置为drawable目录下自己定义的xml文件,在文件中生命按下和未按下的图片显示
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:drawable="@drawable/map_position1" android:state_pressed="true"></item><item android:drawable="@drawable/map_position0"></item></selector>
也可以设置为drawable文件夹下的图片名称
//android:src = "@drawable/图片名称"
4.TableLayout
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="0,2" android:shrinkColumns="1">
需要注意定义中的第三行和第四行
第三行:stretchColumns属性,将这个tablelayout中的相应行进行拉伸,使其将剩余的宽度控件占满—有空就填满
第四行:shrinkColumns属性,如果有一行的内容过多需要换行时使用,此属性可以在保证其余行最佳尺寸的情况下,对当前行进行换行—放不下要换行
<TableRow android:layout_width="match_parent" android:layout_height="wrap_content" >
width属性一般设置为match_parent
height属性一般设置为wrap_content
5.DatePicker
<DatePicker android:layout_width="wrap_content" android:layout_height="wrap_content" />
6.TimePicker
<TimePicker android:layout_width="wrap_content"
上述两个控件在使用时需要什么样的样式自行调用,需要注意的是他们在不同的Android版本上有很不一样的界面
7.SeekBar
<SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="30"/>
max属性设置总长,progress属性设置已经拉取的长度的比例
8.ProgressBar
<ProgressBar style="@android:styleWidget.ProgressBar.Horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progress="30"
max,progress属性和上述控件相同,secondaryProgress表示将要progress的进度,表示为灰度显示,style属性表示这个控件为横向的进度条形状
9.HorizontalScrollView
<HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" >
这个控件表示水平方向上的有滚动条,其他属性和ScrollView保持一致
10.ToggleButton
<ToggleButton android:layout_width="match_parent" android:layout_height="wrap_content" android:checked="true" android:textOn="@string/basketball" android:textOff="@string/football"/>
这个控件可以在选中和未被选中时显示不同的文字内容
11.CheckBox
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/selector_checkbox2" android:button="@null" android:checked="true" android:gravity="center" android:text="是否开启网络" />
复选框
background属性可以为图片资源或者自己定义的xml文件
将button属性设置为null时不显示最前边的小框,为了修改这个小框的图片,做法和设置background的方法一致
gravity属性文字放在background的位置
12.ImageView,TextView,EditText
<ImageView android:id="@+id/map_position" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/selector_position" android:visibility="visible" /><TextView android:id="@+id/map_title" android:layout_width="100dp" android:layout_height="wrap_content" android:background="@color/yellow" android:gravity="center" android:padding="5dp" android:text="@string/hello_world" android:textColor="@color/red" android:textSize="@dimen/font_middle" /><EditText android:layout_width="match_parent" android:layout_height="match_parent" android:hint="请输入密码" android:inputType="textPassword" android:maxLength="8" android:padding="5dp" android:singleLine="true" android:textColor="@color/red" android:textColorHint="@color/yellow" android:textSize="@dimen/font_middle" />
13.RadioGroup
<RadioGroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/selector_checkbox" android:text="水果" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@drawable/selector_checkbox" android:checked="true" android:text="咖啡" /> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/selector_checkbox2" android:button="@null" android:gravity="center" android:text="猴子" /></RadioGroup>
需要设置方向为水平,在RadioGroup中放置RadioButton就可以实现单选的功能
0 0
- android控件与常用控件
- android 常用控件 时钟控件
- android控件与常用控件
- Android 常用控件讲解 --控件
- Android常用控件
- Android常用控件-spinner
- Android常用控件-AutoCompleteTextView
- android常用控件(转)
- android 的常用控件
- Android常用控件总结
- Android常用控件总结
- Android控件常用属性
- Android常用控件总结
- Android常用控件总结
- Android控件常用属性
- Android常用控件总结
- android常用控件属性
- android 常用控件
- Box2d源码学习<十二>b2Collision之碰撞(上)公共部分的实现
- [整体二分 || 树套树 || 点分治] BZOJ 4009 [HNOI2015]接水果
- 欢迎使用CSDN-markdown编辑器
- redis常见的五种数据类型
- 欢迎使用CSDN-markdown编辑器
- Android常用控件
- Android防止事件重复提交
- 关于linux启动
- 杭电 2053(循环)
- Python项目中基础知识回顾之路(2)
- [Ruby笔记]3. 语法检查ruby -cw xx.rb /代码运行 ruby xx.rb/变量约定 @ @@ $
- linux-vim 文本编辑器快捷键--附键位分布图
- XMPPFramework,编译失败,@import libxmlSimu后提示:Module 'libxmlSimu' not found
- Box2d源码学习<十三>b2Collision之碰撞(下) 具体形状间的碰撞的实现