Android常用控件
Android控件的相同属性
- 所有控件都有的4个属性:id、layout_width以及layout_height和android:visibility;
Butoon
- Butoon控件是Android程序开发中最常用的控件之一主要功能是通过单机Button来触发来完成一系列的事件,然后加上监听器来实现监听事件。
以下展示一些常见的属性。
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="点击开始"
android:id="@+id/bt_ks"
android:background="@color/colorAccent"/>
- ImageButton控件是图片控件,同Button控件相似都是通过点击当前控件来触发一系列事件,加上监听器来实现监听事件。
以下展示一些常见的属性。
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Im_sc"
android:layout_marginTop="100dp"
android:src="@mipmap/ic_launcher"/>
TextView
- TextView也是 Android 程序开发中最常用的控件之一,主要功能是向用户展示文本的内容,它是不可编辑的 ,只能通过初始化设置或在程序中修改。
以下展示一些常见的属性。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名:"
android:textSize="20dp"
android:id="@+id/tv_name"
/>
EidtView
- EidtView与TextView相似,不过EidtView是可以编辑的,可以和用户进行 交互。
以下展示一些常见的属性。
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入您的名字"
android:textSize="20dp"
/>
ImageView
- ImageView是一个图片控件,负责显示图片,既可以用系统提供的资源文件,也可以用 Drawable 对象,且ImageView和ImageButton, 很多属性都是相同的。
以下展示一下常见的属性。
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/Iv_tp"
android:scaleType="fitXY"
/>
CheckBox
- CheckBox是复选按钮,是一种可以进行多选的按钮,默认以矩形表示。它有选中或者不选中双状态。我们可以先在布局文件中定义多选按钮, 然后对每一个多选按钮进行事件监听 setOnCheckedChangeListener,通过 isChecked 来判断 选项是否被选中,做出相应的事件响应。
<CheckBox
android:id="@+id/cb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="九江"
android:textSize="30sp"
android:textColor="#0000FF"
android:textStyle="normal" />
<CheckBox
android:id="@+id/cb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="南昌"
android:textSize="30sp"
android:textColor="#0000FF"/>
ProgressBar
- ProgressBar 用于在界面上显示一个进度条,表示我们的程序正在加载一些数据,运行程序,会看到屏幕中有一个圆形进度条正在旋转。
以下展示一些常见的属性。
<ProgressBar
android:id="@+id/pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/bt_ks" />