ImageView、RadioButton、CheckBox等控件学习
2015-09-22 21:40
501 查看
1、ImageView用于编辑显示图片控件,在调整一张片的情况下,属性layout_width和layout_height应设置为match_parent,不然可能会使图片无法满屏。
同时设置图片是用属性src,虽然用background同样能让一张图片设置在屏幕中,但是,当调整图片时可能会使图片变形。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/animal"
此段代码则可表示放上一张图片,若放多张图片,则需要使用gridview调用适配器完成,使图片达到缩放不变形的效果,这个下次再另外叙述
2、RadioButton单选控件,但在使用时应该配合RadioGroup一起使用,不然会出现同时选中的情况,系统默认的格式,例如
<RadioGroup
android:id="@+id/sex_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- android:checked="true" 设置默认选中 -->
<RadioButton
android:id="@+id/man_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/man_radio"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/woman_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/woman_radio"
android:textSize="20sp"/>
</RadioGroup>
RadioButton自定义格式可通过自定义背景图形格式来形成
<RadioButton
android:id="@+id/man_2_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/man_radio"
android:background="@drawable/sex_button_selector" <!-- 自定义资源selector 显示选中与没有选中的区别,定义自己的格式 -->
android:gravity="center"
android:button="@null" <!-- 消除本来系统定义的格式 -->
android:layout_marginTop="10dp"
android:textSize="20sp"
/>
3、CheckBox多选控件
实现代码如下
<CheckBox
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onChickClick" <!-- 定义点击方法名,在Java代码中定义此方法,当选中时获取信息 -->
android:text="@string/first" />
自定义格式同RadioButton
4、ToggleButton和Switch,开关控件,前者为点击时改变状态,后者为滑动改变状态,
android:textOff="关"
android:textOn="开"
需要说的是当要获取switch的值时,尽量不要用onclick属性来定义方法名来获取,因为此时为点击才回获取值,
滑动时则不能获取。因此需要在Java代码中以实现接口的形式调用OnCheckedChangeListener()方法
同时设置图片是用属性src,虽然用background同样能让一张图片设置在屏幕中,但是,当调整图片时可能会使图片变形。
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/animal"
此段代码则可表示放上一张图片,若放多张图片,则需要使用gridview调用适配器完成,使图片达到缩放不变形的效果,这个下次再另外叙述
2、RadioButton单选控件,但在使用时应该配合RadioGroup一起使用,不然会出现同时选中的情况,系统默认的格式,例如
<RadioGroup
android:id="@+id/sex_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- android:checked="true" 设置默认选中 -->
<RadioButton
android:id="@+id/man_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/man_radio"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/woman_radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/woman_radio"
android:textSize="20sp"/>
</RadioGroup>
RadioButton自定义格式可通过自定义背景图形格式来形成
<RadioButton
android:id="@+id/man_2_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/man_radio"
android:background="@drawable/sex_button_selector" <!-- 自定义资源selector 显示选中与没有选中的区别,定义自己的格式 -->
android:gravity="center"
android:button="@null" <!-- 消除本来系统定义的格式 -->
android:layout_marginTop="10dp"
android:textSize="20sp"
/>
3、CheckBox多选控件
实现代码如下
<CheckBox
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onChickClick" <!-- 定义点击方法名,在Java代码中定义此方法,当选中时获取信息 -->
android:text="@string/first" />
自定义格式同RadioButton
4、ToggleButton和Switch,开关控件,前者为点击时改变状态,后者为滑动改变状态,
android:textOff="关"
android:textOn="开"
需要说的是当要获取switch的值时,尽量不要用onclick属性来定义方法名来获取,因为此时为点击才回获取值,
滑动时则不能获取。因此需要在Java代码中以实现接口的形式调用OnCheckedChangeListener()方法
相关文章推荐
- 关于形如--error LNK2005: xxx 已经在 msvcrtd.lib ( MSVCR90D.dll ) 中定义--的问题分析解决
- HDU 1248 寒冰王座
- POJ 3660 Cow Contest 最短路floyd
- NAT介绍,防火墙介绍
- 深度学习Matlab工具箱代码注释——cnntrain.m
- 机器学习笔记 贝叶斯学习(上)
- cocos2d-x学习笔记(五)接入百度联盟广告(Android横幅和插屏广告)
- java中double保留小数点
- Oracle 11g安装过程出现“未找到文件”
- 在恩典中生活
- css的优先级
- 【CSS】CSS HTML 常用命名单词
- Html加载swf 兼容IE8 (含以下)显示
- WKT、SRID、EPSG概念
- 自定义Tree
- 二叉树的中序遍历
- main 函数自身递归调用+感想
- maven 学习总结(六)——Maven与Eclipse整合
- 面试题5:从尾到头打印链表
- 个人项目——四则运算题目的随机生成