一、相对布局思维导图
二、知识点
- text 设置文本内容
- layout_width 组件宽度
- layout_height 组件高度
- id 设置一个组件id,通过findViewById()的方法获取到该对象,然后进行相关设置
- background 背景颜色(或背景图片)
- textColor 设置字体颜色
- textStyle 设置字体样式
- textSize 字体大小
- layout_centerHorizontal 该控件设置在相对于父控件水平居中的位置
- layout_marginTop 指定该属性所在控件距上部最近控件的最小值
- layout_marginBottom 指定该属性所在控件距下部最近控件的最小值
- layout_marginLeft 指定该属性所在控件距左边最近控件的最小值
- layout_marginRight 指定该属性所在控件距右边最近控件的最小值
- LinearLayout 对齐方式,center_vertical(垂直居中)、center_horizontal(水平居中)、center
- gravity 控制控件内文字的对齐方式
- android:hint 输入框 指定提示语
三、创建安卓应用
四、主布局资源文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".register">
<TextView
android:id="@+id/tv_user_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/registered"
android:textColor="#07BCFC"
android:textSize="35dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_name"
android:text="@string/name"
android:textColor="@color/colorPrimary"
android:textSize="20dp"
android:layout_gravity="left"
android:layout_marginTop="190dp"/>
<EditText
android:id="@+id/edt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="180dp"
android:ems="10"
android:hint="@string/input_username"
android:singleLine="true" />
<TextView
android:id="@+id/tv_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:text="@string/password"
android:textSize="20dp"
android:layout_gravity="left"
android:layout_marginTop="230dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt_password"
android:ems="10"
android:hint="@string/input_password"
android:singleLine="true"
android:inputType="textPassword"
android:layout_marginLeft="80dp"
android:layout_marginTop="220dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_phone"
android:text="@string/phone"
android:textColor="@color/colorPrimary"
android:textSize="20dp"
android:layout_gravity="left"
android:layout_marginTop="270dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt_phone"
android:ems="10"
android:inputType="phone"
android:hint="@string/input_phone"
android:singleLine="true"
android:layout_marginLeft="80dp"
android:layout_marginTop="260dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_email"
android:text="@string/email"
android:textColor="@color/colorPrimary"
android:textSize="20dp"
android:layout_gravity="left"
android:layout_marginTop="310dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edt_email"
android:ems="10"
android:hint="@string/input_email"
android:inputType="textEmailAddress"
android:singleLine="true"
android:layout_marginLeft="80dp"
android:layout_marginTop="300dp"/>
<TextView
android:id="@+id/tv_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gender"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:layout_gravity="left"
android:layout_marginTop="350dp"/>
<RadioGroup
android:id="@+id/rg_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="80dp"
android:layout_marginTop="340dp">
<RadioButton
android:id="@+id/rb_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/male" />
<RadioButton
android:id="@+id/rb_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="@string/female" />
</RadioGroup>
<TextView
android:id="@+id/tv_hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hobby"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:layout_gravity="left"
android:layout_marginTop="390dp"/>
<RadioGroup
android:id="@+id/rg_hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="80dp"
android:layout_marginTop="380dp">
<CheckBox
android:id="@+id/cb_music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/travel" />
<CheckBox
android:id="@+id/cb_read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/read" />
<CheckBox
android:id="@+id/cb_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/food" />
</RadioGroup>
<Button
android:id="@+id/btn_ok"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:onClick="doOK"
android:text="@string/ok"
tools:ignore="OnClick"
android:layout_marginLeft="20dp"
android:layout_marginTop="430dp"
/>
<Button
android:id="@+id/btn_reset"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:onClick="doReset"
android:text="@string/reset"
tools:ignore="OnClick"
android:layout_marginLeft="200dp"
android:layout_marginTop="430dp"/>
</RelativeLayout>
五、字符串资源文件strings.xml
<resources>
<string name="app_name">xiangduibuju</string>
<string name="registered">注册个人信息</string>
<string name="name">用户名:</string>
<string name="input_username">请输入用户名</string>
<string name="password">密码:</string>
<string name="input_password">请输入密码</string>
<string name="phone">电话:</string>
<string name='input_phone'>请输入电话号码</string>
<string name="email">邮箱:</string>
<string name="input_email">请输入电子邮箱</string>
<string name="gender">性别:</string>
<string name="male">男</string>
<string name="female">女</string>
<string name="hobby">爱好:</string>
<string name="travel">旅行</string>
<string name="read">阅读</string>
<string name="food">美食</string>
<string name="ok">提交</string>
<string name="reset">重置</string>
</resources>