Android 入门第一讲02-线性布局LinearLayout(核心属性,嵌套,微信登录ui案例实现)

Android 入门第一讲02-线性布局LinearLayout(核心属性,嵌套,微信登录ui案例实现)


Android 入门第一讲01-安卓介绍+UI介绍(新建as项目,ui开发常见控件介绍,布局介绍)

1.LinearLayout的核心属性

1. android:orientation—.设置布局的排列方向

horizontal为水平方向
在这里插入图片描述
vertical为垂直方向
在这里插入图片描述

2. android:layout_weight—设置控件占剩余空间的权重
例如
在这里插入图片描述
3. android:gravity–控件内容在控件中的位置
例如
在这里插入图片描述
4.android:layout_gravity—控件处于布局中的位置(要加在子控件里面)
例如
在这里插入图片描述

2.LinearLayout的嵌套

在这里插入图片描述
LinearLayout的原理是将控件串在一起,要实现文字上面放图片,我们可以用LinearLayout的嵌套来完成
在这里插入图片描述
在LinearLayout里面嵌套四个LinearLayout
案例实现

我这里犯了一个小错误:0dp只有在约束布局里面存在。

3.微信登录ui案例实现

在这里插入图片描述
代码如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" 

    android:layout_height="match_parent"
    tools:context=".MainActivity">
<Button
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:background="@mipmap/stop"
    android:layout_margin="10dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="微信号/QQ/邮箱登录"
        android:textSize="32dp"
        android:textColor="#000000"
        android:layout_marginLeft="25dp"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="120dp"
            android:layout_height="match_parent"
            android:text="账号"
            android:textColor="#000000"
            android:textSize="24sp"
            android:gravity="center"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:hint="请填写微信号/QQ号/邮箱"/>



    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:orientation="horizontal">
        <TextView
            android:layout_width="120dp"
            android:layout_height="match_parent"
            android:text="密码"
            android:textColor="#000000"
            android:textSize="24sp"
            android:gravity="center"/>
        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:hint="请填写密码"/>



    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="用手机号登陆"
        android:layout_marginLeft="40dp"
        android:textColor="#7D8BA8"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_margin="20dp"
        android:text="登陆"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="150dp"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="right"

            android:text="找回密码"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1"

            android:text="紧急冻结"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"

            android:text="微信安全中心"/>


    </LinearLayout>


</LinearLayout>

运行结果
在这里插入图片描述

存在的问题

在这里插入图片描述

原因:线性布局在 定义了垂直布局的情况下,控件只能定义与顶部的边距,针对不同的的屏幕是不行的,所以线性布局无法实现。

!!!那怎样才能解决这个问题变得更加美观呢,那就请看下一讲,大哥大二号小弟相对布局,感谢您的阅读
Android 入门第二讲01-获取指定app的图片+按钮属性(圆角,背景颜色,边框)
对了这里推荐一个很好用的图标网站(超赞)
https://www.iconfont.cn/home/index?spm=a313x.7781069.1998910419.2
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_46526828/article/details/107009159
今日推荐