这段代码的关键主要是在我们的相对布局以及线性布局上面,我们首先在总体布局里设置为线性布局,然后再在里面设置为相对布局,这是一个十分常见的XML布局模式。
废话不多说,直接上代码:
一.activity.xml
<?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="@drawable/bg2"
>
<!--头部内容-->
<RelativeLayout android:layout_width="match_parent" android:layout_height="160dp" android:padding="16dp" android:layout_margin="0dp"
>
</RelativeLayout>
<!--输入框-->
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" android:layout_margin="0dp"
>
<EditText android:id="@+id/account" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:hint="QQ号/密码/邮箱"/>
/>
<EditText android:layout_below="@id/account" android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:password="true" android:hint="密码"/>
/>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent" android:layout_height="33dp" android:padding="0dp" android:layout_margin="0dp"
>
<CheckBox android:id="@+id/remember_pass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住密码"/>
</RelativeLayout>
<!--密码功能-->
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="16dp">
<Button android:id="@+id/login" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:textColor="#fff" android:background="#008cc9"/>
<Button android:id="@+id/forget_pwd" android:layout_below="@id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:textColor="#2999ce" android:gravity="start" android:layout_marginTop="16dp" android:textSize="16dp" android:text="忘记密码?"/>
<Button android:id="@+id/register" android:layout_below="@id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:textColor="#2999ce" android:gravity="end" android:text="新用户注册" android:layout_marginTop="16dp" android:textSize="16dp" android:layout_al