laogui 发表于 2023-3-15 19:27:02

【EasyClick】【安卓UI】XML 基础教程~基本控件认识二

XML 基础教程~基本控件认识
教程原址:原生UI之常用控件二

CheckBox 复选框说明复选框控件,用来让用户多个选择的控件.私有属性


属性名说明可选值
layout_weight子元素权重数字
当父级为LinearLayout的时候,子控件可以设置权重
gravity内部的控件对齐方式top
bottom
left
right
center_vertical
fill_vertical
center_horizontal
fill_horizontal
center
fill
clip_vertical
clip_horizontal
checked是否选择true:选中 false:不选中
text文字字符串
textColor文字颜色16进制,例如#FFFFFF
textSize文字大小具体数字+dp
例子   

<!-- 例子-->
<CheckBox android:tag="cb0"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="复选框0" />


RadioButton 单选按钮说明单选按钮控件,用来让用户单选的控件注意单选按钮需要配合单选布局实现单选效果私有属性

属性名说明可选值
layout_weight子元素权重数字
当父级为LinearLayout的时候,子控件可以设置权重
gravity内部的控件对齐方式top
bottom
left
right
center_vertical
fill_vertical
center_horizontal
fill_horizontal
center
fill
clip_vertical
clip_horizontal
checked是否选择true:选中 false:不选中
text文字字符串
textColor文字颜色16进制,例如#FFFFFF
textSize文字大小具体数字+dp
例子      
'
<!--例子-->
<RadioButton android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:text="单选框1"                     android:textSize="15sp"                     android:gravity="center"                     android:checked="true" />



Spinner 下拉选择框说明下拉选框


属性名说明可选值
layout_weight子元素权重数字
当父级为LinearLayout的时候,子控件可以设置权重
gravity内部的控件对齐方式top
bottom
left
right
center_vertical
fill_vertical
center_horizontal
fill_horizontal
center
fill
clip_vertical
clip_horizontal
text下拉文字字符串
多个下拉选项用竖线分隔,例如:选项1|选型2
textColor文字颜色16进制,例如#FFFFFF
textSize文字大小具体数字+dp
defaultText默认选择的数据text中的某一项
popupHeight弹出框高度具体数字+dp
例子      

<!--例子-->
<Spinner android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:text="选择1|选择2"                     android:textSize="15sp"                     android:gravity="center"                     android:defaultText="选择1"/>



Swtich 开关按钮说明开关按钮私有属性

属性名说明可选值
layout_weight子元素权重数字
当父级为LinearLayout的时候,子控件可以设置权重
gravity内部的控件对齐方式top
bottom
left
right
center_vertical
fill_vertical
center_horizontal
fill_horizontal
center
fill
clip_vertical
clip_horizontal
checked是否选择true:选中 false:不选中
text文字字符串
textColor文字颜色16进制,例如#FFFFFF
textSize文字大小具体数字+dp
例子      <!--例子-->      <Switch android:layout_width="match_parent"                android:layout_height="wrap_content"                android:text="开关"                android:textSize="15sp"                android:gravity="center"                android:checked="true" />Copy


ImageView 图像说明图像控件私有属性

属性名说明可选值
src图像地址字符串
HTTP的URL或者IEC文件中的图像项目中res目录下的图像资源文件(@drawable/aaa这样的写法)
scaleType图像缩放方式fitXY
fitCenter 默认
fitEnd
fitStart
center
centerCrop
centerInside
matrix
缩放方式参考:参考链接
例子      


<!--引用iec资源-->
<ImageView android:layout_width="match_parent"                   android:layout_height="wrap_content"                   android:src="@drawable/a" />
<!--引用网络资源图片地址-->
<ImageView android:layout_width="match_parent"                   android:layout_height="wrap_content"                   android:src="http://baidu.com" />


WebView 内嵌浏览器说明WebView 内嵌浏览器,支持 H5 和 JS 操作私有属性

属性名说明可选值
url网页地址支持layout内部的html,也支持http网络上的html
例子      



<!--第一种 加载 layout 文件夹中的 html-->
<WebView android:layout_height="wrap_parent"               android:layout_width="match_parent"               android:url="main.html"/>
<!--第二种网络上的 html-->
<WebView android:layout_height="wrap_parent"               android:layout_width="match_parent"               android:url="https://www.baidu.com"/>


页: [1]
查看完整版本: 【EasyClick】【安卓UI】XML 基础教程~基本控件认识二