UI常用控件

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”/>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值