前言:

https://mp.csdn.net/mdeditor/92801025# <https://mp.csdn.net/mdeditor/92801025#>

android在xml布局中共用的属性有:

宽度:layout_width(必须要有)

高度:layout_height(必须要有)

用于唯一识别的id:id

背景颜色:background

内部组件是否居中:gravity

控件是否可见:android:visibility

外边距:

距离上边距:layout_marginTop

距离左边距:layout_marginLeft=""

距离右边距:layout_marginRight=""

距离下边距:layout_marginBottom=""

距离四边的距离 :layout_margin=""

内边距:

距离四边的距离:padding=""

距离左边距:paddingLeft=""

距离上边距:paddingTop=""

距离右边距:paddingRight=""

距离下边距:paddingBottom=""

常用控件

TextView



 

 

 

文本框,主要用于文本的展示

                   常用属性: android:text:设置文本内容

                                       android:textColor:设置文本颜色

                                       android:drawableTop:在文本上部显示图片

                                       android:drawableBottom:在文本底部显示图片

                                       android:drawableLeft:在文本左部显示图片

                                       android:drawableRight:在文本右部显示图片

                                       android:textSize:设置字体大小

         说明:
java代码中获取文本框中的内容,即text属性中的值使用getText()方法,设置text的是使用setText(“文本内容”)方法。例子在CommonControls项目中的“文本框”,源码在CommonControls/
contrls/TextviewActivity.java及对应的xml文件

EditText



编辑框,继承自TextView, 支持TextView的各种属性及方法,用于在手机上显示收集文本

                   常用属性:android:text:设置文本内容

                                       android:textColor:设置文本颜色

                                       android:drawableTop:在文本上部显示图片

                                       android:drawableBottom:在文本底部显示图片

                                       android:drawableLeft:在文本左部显示图片

                                       android:drawableRight:在文本右部显示图片

                                       android:textSize:设置字体大小

                                       android:hint:设置提示文本

                                       android:focusable:设置是否获取焦点

说明
:hint和text都是用于设置文本内容的,他们的区别在于hint属性在用户输入内容后会自动清除掉hint中的内容,而text属性则不会自动清除。如例子CommonControls项目下的编辑框中的演示,源码在CommonControls/
contrls/EdittextActivity.java及其对应的xml文件。

Button



普通按钮,继承自Textview, 支持TextView的各种属性及方法,一般用于触发点击事件

常用属性:android:text:设置文本内容

                                       android:textColor:设置文本颜色

                                       android:drawableTop:在文本上部显示图片

                                       android:drawableBottom:在文本底部显示图片

                                       android:drawableLeft:在文本左部显示图片

                                       android:drawableRight:在文本右部显示图片

                                       android:textSize:设置字体大小

说明:如在项目CommonControls下的click包下使用Button做了点击事件的四种方式

ImageView



图像视图,用于在屏幕中展示Drawable图像,平常主要用于展示图片

                   常用属性:android:src:设置imageview中drawable对象的id

说明
:src和background不同,background是背景填充,即控件多大,背景就多大,图片容易因为控件的比例失真或者变形,例子在项目CommonControls/
contrls/ImageViewActivity.java及对应的xml文件。

ImageButton

         图像按钮,基本属性类似于imageview,不在赘述

CheckBox



         复选框,继承自Button,支持Button的各种属性

                   常用属性:android:checked:默认状态,true默认选中,false不选中,如果不设置,默认不选中

         说明:
setChecked()方法设置选中,isChecked()判断选中状态。如例子CommonControls项目下的多选框演示,源码在CommonControls/
contrls/CheckBoxActivity.java及其对应的xml文件。

RadioButton



         单选按钮,继承自CompoundButton
<https://developer.android.google.cn/reference/android/widget/CompoundButton.html>
,CompoundButton
<https://developer.android.google.cn/reference/android/widget/CompoundButton.html>
又继承自Button,因此RadioButton具有button的所有属性。

常用属性:android:checked:默认状态,true默认选中,false不选中,如果不设置,默认不选中

         说明
:setChecked()方法设置选中,isChecked()判断选中状态,如例子CommonControls项目下的单选框演示,源码在CommonControls/
contrls/RadioButtonActivity.java及其对应的xml文件。

代码已上传百度云

链接:https://pan.baidu.com/s/1YEV3ewnog3J2Xu1Ta2c6uw 
提取码:gd6l 

个人微信公众号:


友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信