TextView
TextView继承了View,他还是EditText和Button两个UI组件的父类。
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_x="120dp"
android:layout_y="200dp"
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="120dp"
android:layout_weight="1"
android:text="我爱你Android"
android:textColor="@color/black"
android:textSize="16sp" />
</AbsoluteLayout>
EditView
EditView(输入框)与TextView相似, 许多的XML属性可以公用,与TextView最大的区别就是EditView可以接受用户的输入。
使用android:hint来提示用户当前文本框要输入的内容是什么。
使用android:inputType属性来设置输入的类型
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_y="50dp"
android:layout_x="70dp"
android:hint="请输入密码"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"
android:inputType="numberPassword" />
自定义样式
custom_edittext_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFFFF"/>
<corners android:radius="3dip"/>
<!-- 圆角-->
<corners android:radius="5dp" />
<!--描边-->
<stroke
android:width="2dip"
android:color="@android:color/holo_blue_light" />
</shape>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_y="50dp"
android:layout_x="70dp"
android:hint="请输入密码"
android:background="@drawable/custom_edittext_background"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"
android:inputType="numberPassword"
/>
Button
Button(按钮)继承了textView,它主要是UI界面上生成一个按钮,用户可以单机按钮,并且能为按钮添加onClick事件即的单击事件。
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_y="200dp"
android:layout_x="100dp"
android:id="@+id/button1"
android:textSize="18dp"
android:text="按钮"/>
ImageView
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="204dp"
android:layout_y="109dp"
android:src="@mipmap/ic_launcher_round" />
<ImageButton
android:id="@+id/imageButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="194dp"
android:src="@mipmap/ic_launcher" />
RadioButton&CheckBox
RadioButton(单选按钮)&CheckBox(复选框),都是继承自Button类,需要和RadioGroup配合使用
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="304dp">
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" />
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="男" />
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_y="400dp">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="422dp"
android:text="NBA" />
<CheckBox
android:id="@+id/checkbox1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="422dp"
android:text="CBA" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="422dp"
android:text="NBL" />
<CheckBox
android:id="@+id/checkbox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="422dp"
android:text="NCAA" />
</RadioGroup>
ProgressBar
ProgressBar(进度条)
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="497dp"/>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="0dp"
android:layout_y="570dp"
android:layout_marginTop="30dp"
android:progress="50"
android:background="@android:color/holo_green_light"/>
SeekBar(拖动条)
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_marginTop="20dp"
android:background="@android:color/holo_green_light"/>