Android studio的UI组件

本文介绍了Android Studio中的几种UI组件,包括文本框组件,详细说明了其文字属性和9patch图片的使用。接着讨论了编辑框组件,允许用户输入文字,并能进行图像属性设置。此外,还讲解了按钮组件,包括文字按钮、图片按钮和单选按钮组,以及如何实现单选按钮的点击事件监听。最后提到了复选框按钮,为开发者提供了更多交互选项。

1.文本框组件

 掌管文字大小,文字来源,文字是否以行的形式显示,对齐方式居中

9patch图片拉伸不变形,需要放在drawable中

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30dp"
        android:text="@string/demo1"
        android:singleLine="true"
        android:gravity="center"/>

 

2.编辑框组件

掌管一些可输入的文字框,这里可以给用户提供输入

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="请输入密码"
    android:inputType="numberPassword"
    />

 在编辑框内绘制图像属性:(相对于文字的方向)

    android:drawableLeft=""左侧
    android:drawableStart=""左侧
    android:drawableBottom=""底部
    android:drawableRight=""右侧
    android:drawableEnd=""右侧
    android:drawableTop=""顶部
搭配
    android:drawablePadding=""配合内边距

3.普通按钮组件

文字按钮:很简单,和上面组件的属性差不多,一样是设置宽高,设置text文本内容<Button>

图片按钮:区别如下<ImageButton/>

android:src="@资源名字"

单选按钮:可以设置单选的内容,checked是默认选中的意思

    <RadioButton
        android:id="@+id/rb_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn2"
        android:text="男"
        android:checked="true"
        />

有时候不止一个单选按钮,所以就需要单选按钮组的出现<RadioGroup><RadioButton>......</RadioGroup>

    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btn2">
        <RadioButton
            android:id="@+id/rb_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:checked="true"
            />
        <RadioButton
            android:id="@+id/rb_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="女"
            />
    </RadioGroup>

设置组的java监听器,点击男的单选框会显示男,点击女的单选框会显示女

        RadioGroup rg= (RadioGroup) findViewById(R.id.rg_1);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton rb= (RadioButton) findViewById(checkedId);
                rb.getText();
                Toast.makeText(DemoMainActivity.this, "性别:"+rb.getText(), Toast.LENGTH_SHORT).show();
            }
        });

 复选框按钮:

    <CheckBox
        android:id="@+id/cb_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="人类"
        android:layout_below="@+id/bt3"
        />
    <CheckBox
        android:id="@+id/cb_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="人"
        android:layout_below="@+id/cb_1"
        />
    <CheckBox
        android:id="@+id/cb_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="类"
        android:layout_below="@+id/cb_2"
        />

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值