Android实现简易登录界面详解

来源:互联网 发布:淘宝信用卡哪个银行好 编辑:程序博客网 时间:2024/06/04 01:36

效果图:

1、选择LinearLayout作为总的布局方式

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.testlogin.MainActivity"

2、编写--用户注册--这一部分,选择textview

 <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:padding="5dp"
        android:textSize="20sp"
        android:text="@string/resister" />

3、编写用户名、密码和两个输入框(选择relativelayout布局)

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/username"
        android:textSize="18sp"
        android:id="@+id/username"/>
    <EditText 
        android:hint="请输入用户名"
        android:inputType="text"
        android:id="@+id/userinput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/username"
        android:layout_alignBaseline="@+id/username"
        android:textSize="18sp"
        android:background="@null"/>

注意:第一个输入框在用户名的右边( android:layout_toRightOf="@+id/username"),密码在用户名下面(       android:layout_below="@+id/username"    )

对齐基准线( android:layout_alignBaseline="@+id/username")。
    <TextView
         android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密    码:"
        android:textSize="18sp"
        android:layout_below="@+id/username"    
        android:layout_marginTop="20dp"    
        android:id="@+id/password"/>
    <EditText 
        android:hint="请输入密码"
        android:paddingLeft="0dp"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/passinput"
        android:layout_toRightOf="@+id/password"
        android:layout_alignLeft="@+id/userinput"
                android:layout_below="@+id/username"        
        android:layout_alignBaseline="@+id/password"
        />
</RelativeLayout>

4、单选按钮 性别部分,选择linearlayout布局,“男”和“女”权重设置为1,就可以平分剩余空间

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:gravity="center_vertical"//设置垂直居中
    >
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="性    别  :"
        android:textSize="18sp"
        
        />
    <RadioGroup 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="男"
            android:layout_weight="1"/>
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="女"/>
    </RadioGroup>
</LinearLayout>

5、爱好和三个checkbox按钮,同样采用LinearLayout布局方式,三个checkbox权重分别设置为1,就可以平分剩余空间

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp">
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="爱    好:"
        android:textSize="18sp"/>
    <CheckBox 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="唱歌"
        android:layout_weight="1"/>
     <CheckBox 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="跳舞"
        android:layout_weight="1"/>
     <CheckBox 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="运动"
        android:layout_weight="1"/>
    
    
</LinearLayout>

6、添加登录按钮

<Button 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="登录"/>

如果有小伙伴觉得我写的对的,请顶一下这篇博文。

原创粉丝点击