制作QQ登录界面

本文介绍了如何制作QQ登录界面,包括程序理解与代码实现。首先分析界面结构,需要一个ImageView展示头像,两个水平线性布局分别包含标题和输入框,以及一个登录Button。在代码实现中,使用RelativeLayout布局,通过调整控件属性实现预期效果。

实验名称

QQ登录界面

实验步骤

1.程序大致理解

在构建UI界面时不要着急动手,首先要考虑准备哪些素材(如:图片资源),会用到哪些控件,把步骤想清楚再动手实践,养成良好的编程习惯在以后开发中会有很大帮助。现在先来看一下QQ登录界面,预览效果如下图所示。

在这里插入图片描述
从图中可以看出,该界面需要一张图片作为QQ头像,因此找到1张图片(head.png)放在drawable文件夹中。在这里插入图片描述
然后分析该界面组成部分,从整体来看界面可分为三部分,第一部分放置1个ImageView控件用于显示头像。在这里插入图片描述
第二部分使用两个水平的线性布局,每个水平布局放置1个TextView控件和1个EditText控件,分别用于显示标题和输入内容。在这里插入图片描述
第三部分放置1个Button按钮用于实现登录。在这里插入图片描述

2.代码实现

总的布局是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=".MainActivity"
    android:orientation="vertical">

</RelativeLayout>

第一部分的ImageView控件用来存放QQ头像

<ImageView
        android:id="@+id/iv"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:background="@drawable/head"/>

第二部分使用两个水平的线性布局,每个水平布局有1个TextView控件和1个EditView控件,分别用来显示标题和输入内容

<LinearLayout
        android:id="@+id/ll_number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/iv"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="15dp"
        android:background="#ffffff">

        <TextView
            android:id="@+id/tv_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="账号:"
            android:textColor="#000"
            android:textSize="20sp"/>

        <EditText
            android:id="@+id/et_number"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:background="@null"
            android:padding="10dp"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll_number"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#ffffff">

        <TextView
            android:id="@+id/tv_password"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="密码:"
            android:textColor="#000"
            android:textSize="20sp"/>

        <EditText
            android:id="@+id/et_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@id/tv_password"
            android:background="@null"
            android:inputType="textPassword"
            android:padding="10dp"/>

    </LinearLayout>

(4)第三部分放1个Button按钮用于实现登录

<Button
        android:id="@+id/btn_login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll_password"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="50dp"
        android:background="#3C8DC4"
        android:text="登录"
        android:textColor="#ffffff"
        android:textSize="20sp"/>

总结

最终效果如下:
在这里插入图片描述
上诉代码看似很多,其实并不复杂,只是把之前学到的知识结合在一起而已,再利用各控件中的属性调试它们的位置和样式。在EditText中android:backgroud="@null"属性值是去掉控件默认的下划线,而Button中android:backgroud="#3C8DC4"属性值为蓝色。

作者:苏思行
原文链接:https://blog.csdn.net/weixin_44719580/article/details/90549642

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值