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

1399

被折叠的 条评论
为什么被折叠?



