Five-People:常用控件及其属性(RadioButton,CheckBox,align,margin,padding)使用方法
来源:互联网 发布:联通网络机顶盒破解 编辑:程序博客网 时间:2024/06/06 07:12
1.CheckBox (多选框):
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/trip"
android:text="@string/trip"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/literature"
android:text="@string/literature"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/design"
android:text="@string/design"/></LinearLayout>
</LinearLayout>
效果图:
2.RadioButton:一组RadioButton必须要放到一个RadioGroup中;
RadioButton只能实现单选;
要给每个RadioButton加ID,否则点击再另一个则显示双选状态
checked赋给RadioButton点击状态
演示:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/male" android:text="男" android:checked="true"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/female" android:text="女"/> </RadioGroup></LinearLayout>效果图:
3.align (RelativeLayout);
android:layout_alignParentBottom 贴紧父元素的下边缘
android:layout_alignParentLeft 贴紧父元素的左边缘
android:layout_alignParentRight 贴紧父元素的右边缘
android:layout_alignParentTop 贴紧父元素的上边缘
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物
android:layout_alignParentStart紧贴父元素结束位置开始
android:layout_alignParentEnd紧贴父元素结束位置结束
代码示例:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<EditText
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/et_item"
android:layout_marginLeft="40dp"
android:background="@drawable/et_item"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/iv_item"
android:background="@mipmap/select"
android:layout_alignRight="@+id/et_item"
android:layout_marginTop="8dp"
android:layout_marginRight="10dp"
android:paddingRight="20dp"
android:paddingBottom="20dp"/>
</RelativeLayout>
</LinearLayout>
4.margin;padding
padding;
5.gravity;
6.layout_gravity:
<LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <RadioGroup android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:layout_marginLeft="15dp" android:layout_marginRight="15dp"> <RadioButton android:layout_width="0dp" android:layout_weight="1" android:background="@drawable/rbtn_selecter" android:layout_height="wrap_content" android:text="学员" android:id="@+id/rbtn_stu" android:checked="true" android:layout_gravity="center_vertical"/> <RadioButton android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="教练" android:id="@+id/rbtn_teach" android:background="@drawable/rbtn_selecter" android:layout_gravity="center_vertical"/> <RadioButton android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="陪练" android:id="@+id/rbtn_partner" android:background="@drawable/rbtn_selecter" android:layout_gravity="center_vertical"/> <RadioButton android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="校长" android:id="@+id/rbtn_president" android:layout_gravity="center_vertical" android:background="@drawable/rbtn_selecter" /> </RadioGroup></LinearLayout>效果图:
Shape:<solid:背景颜色>
< Stroke:对边框的颜色,宽度的设置>
<corners:弧度角,radius=“2px”>
在drawable中:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#00ffff"></solid> <stroke android:color="#000000" android:width="10px"></stroke></shape>应用到控件中:
<EditText android:layout_width="200dp" android:layout_height="60dp" android:id="@+id/et_item" android:layout_marginLeft="40dp" android:background="@drawable/et_item" />效果图:
- Five-People:常用控件及其属性(RadioButton,CheckBox,align,margin,padding)使用方法
- Android关于margin、align、padding等一些常用的属性
- padding和margin的区别及其属性
- 常用控件RadioButton/CheckBox/Toast
- Android常用控件(一)【RadioGroup、RadioButton、CheckBox、Toast】
- [android]控件CheckBox/RadioGroup/RadioButton的常用属性---单复选控件
- android常用控件------checkBox RadioButton ImageView Spinner
- padding 与 margin 属性
- Android中控件的padding和margin属性的使用
- 浅析Margin和Padding属性
- Android margin 和 padding 属性
- margin、padding的属性值
- margin和padding属性特点
- Android-基本控件(CheckBox,RadioGroup,RadioButton)
- Android控件CheckBox、RadioButton
- margin 属性 padding属性 div属性
- (转)android常用控件(二) RadioGroup RadioButton CheckBox Toast的使用
- 4.Android 游戏开发常用的系统控件(EditText、CheckBox、Radiobutton)
- AngularJS学习笔记—事件指令
- POJ3176-Cow Bowling
- 第八周项目三 指向学生类的指针
- ibatis 中的#与$
- WebSocket(1)-- WebSocket API简介
- Five-People:常用控件及其属性(RadioButton,CheckBox,align,margin,padding)使用方法
- virual box快速安装max系统
- Caffe+Ubuntu14.04+CUDA7.5安装笔记
- 获取java中src目录的方法
- HDU 4411 Arrest 费用流
- WebSocket(2)--为什么引入WebSocket协议
- android仿qq聊天界面的的布局适配器的写法
- View的事件分发机制
- 专业版V9.1SP1提示"运行时错误,-2147417848(80010108)