AndroidStdio RelativeLayout相对布局写一个注册界面

AndroidStdio RelativeLayout相对布局写一个注册界面

先看效果图:

在这里插入图片描述

注册界面包括两部分,上面的图片区和下面的表单区。图片区包含一个ImageView,表单区包含昵称文本框,昵称输入框,密码文本框,密码输入框,确认密码文本框,确认密码输入框和一个注册按钮。完整代码放在最下面。下面简单说一下RelativeLayout相对布局。

概览

相对布局是组件相对于某个参照组件进行布局的方式,它比线性布局更加灵活。可以是父组件和子组件之间,也可以是子组件和子组件之间。

父子之间的相对布局

常用的有如下一些:

在这里插入图片描述

示例效果:
在这里插入图片描述

兄弟之间的相对布局

常用的有如下一些:
在这里插入图片描述

示例效果:
在这里插入图片描述

注册界面代码

<?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=".RegisterActivity">

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="304dp"
        app:srcCompat="@drawable/register" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/imageView3"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:text="昵称"/>

    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView5"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:text="密码" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView6"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:inputType="" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/password"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="20dp"
        android:text="确认密码" />

    <EditText
        android:id="@+id/password2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/textView7"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="10dp"
        android:ems="10"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/buttonRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="40dp"
        android:background="@color/colorRegister"
        android:text="注册" />

</RelativeLayout>
out_marginBottom="40dp"
        android:background="@color/colorRegister"
        android:text="注册" />

</RelativeLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值