当前位置: 移动技术网 > 移动技术>移动开发>Android > UI常用控件

UI常用控件

2020年07月08日  | 移动技术网移动技术  | 我要评论

1.控件分类
Textview,edittext,button,radiobutton,imageview
2.TextView是用于显示文字(字符串的控件,可在代码中通过设置属性改变文字的大小颜色、样式等功能。
< TextView
android:layout width=”match_ parent"
android:layout_ height= “wrap_ content”
android:text= "Hello World!
android:textC olor= "#000000
android:textSize= “25sp’
android:gravity= " center’
/>
3.EditText继承自TextView,可以进行编辑操作,将用户信息传递给Android程序。还可以为EditText控件设置监听器,用来测试用户输入的内容是否合法。
< EditText
android:layout width= " match_ parent
11
android:layout height= “wrap_ content
android:hint= “请输入姓名”
android:maxLines=” 2”
android:textColor= : “#000000”
android:textSize= " 20sp ’
android:textStyle=“italic’
/>
4.Button是按钮,是用于响应用户的一系列点击事件,使程序更加流畅和完整。
< Button
android:id= “@ + id/btn’
android:text= “按钮’
android:layout_ width=”match_ parent”
android:layout_ height= “wrap_ content”
android:onClick=”click”
/>
5.RadioButton为单选按钮,它需要与RadioGroup配合使用,提供两个或多个互斥的选项集。
RadioGroup是单选组合框,可容纳多个RadioButton,并把它们组合在-起,实现单选状态。
< RadioGroup .
android:layout_ width=” match_ parent”
android:layout height= “wrap_ content”
android:orientation= “vertical”>
< RadioButton
android:layout width= “wrap_ content”
android:layout height= “wrap_ content "
android:text=“男”/>
< RadioButton
android:layout_ width=’ wrap_ content”
android:layout height= “wrap_ content”
android:text=“女“/>

利用setOnCheckedChangeListener()监听RadioGroup控件状态,通过if语句判断被选中RadioButton的id.
radioGroup.setOnCheckedChangeListener(new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedld) {
if (checkedld == R.id.rbtn) {
textView.setText(“您的性别是:男”);
} else {
textView.setText(“您的性别是:女”);
);
6.ImageView是视图控件,它继承自View, 其功能是在屏幕中显示图像。ImageView类可以从各种来源加载图像(如资源库或网络),并提供缩放、裁剪、着色(渲染) 等功能。
< ImageView
android:layout_ width= “wrap_ content”
android:layout_ height= “wrap_ content”
android:background= " @drawable/bg” />
< ImageView
android:layout_ width= "100dp’
android:layout_ height= “100dp’
android:srC= " @ android:drawable/sym_ def_ app icon”/>

本文地址:https://blog.csdn.net/qq_46372637/article/details/107164468

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网