实验目的:掌握常用布局
实验内容:分别使用(根布局)RelativeLayout和LinearLayout实现:
实验内容一、用RelativeLayout实现
Register.xml: (res->layout)
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:text="@string/username"/>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="@+id/textview1"
android:hint=""
android:inputType="number"
android:background="#FFFFFF"/>
<TextView
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:text="@string/password"
android:textColor="#FFFFFF"
android:layout_height="25dp"
android:textSize="20sp"
android:layout_below="@+id/editText1"/>
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="@+id/textview2"
android:hint=""
android:inputType="number"
android:background="#FFFFFF"/>
<Button
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_toLeftOf="@+id/quxiao"
android:gravity="left"
android:text="@string/enter"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/quxiao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignRight="@+id/editText2"
android:gravity="left"
android:textColor="#FFFFFF"
android:text="@string/quxiao"/>
</RelativeLayout>
Strings.xml:(res->values)
<?xml version="1.0"encoding="utf-8"?>
<resources>
<string name= "app_name">Chapter3</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="username">请输入用户名:</string>
<string name="password">请输入密码:</string>
<string name="enter">确认</string>
<string name="quxiao">取消</string>
</resources>
实验内容二、用RelativeLayout实现
Register1.xml:(res->layout)
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:text="@string/username"/>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:hint=""
android:inputType="number"
android:background="#FFFFFF"/>
<TextView
android:id="@+id/textview2"
android:layout_width="match_parent"
android:text="@string/password"
android:textColor="#FFFFFF"
android:layout_height="25dp"
android:textSize="20sp"/>
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:hint=""
android:inputType="number"
android:background="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
android:layout_weight="2.5">
<Button
android:id="@+id/enter"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/enter"
android:gravity="left"
android:textColor="#FFFFFF"
/>
<Button
android:id="@+id/quxiao"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/quxiao"
android:gravity="left"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</LinearLayout>