安卓APP布局——线性布局

目录

一、介绍(LinearLayout)

二、常用属性

三、权重(weight)​​​​​​​

四、分割线

五、制作一个页面(登录)


一、介绍(LinearLayout)

  • 只能在横线或竖线放置,默认横线放置
  • 容易对齐,应用在登录界面

二、常用属性

  1. orientation 控制横线放置还是竖线放置
    horizontal,横线放置
    vertical,竖线放置
  2. gravity
    针对组件
    可以使用|多个参数组合
     
    android:gravity="center|center_horizontal"
  3. layout_gravity
    layout控件本身
  4. width,heigh,id,background,和相对布局的一样用法

三、权重(weight)

把布局平均分

代码理解,实现

<RelativeLayout 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:background="@drawable/bg_shopping_menu"
    tools:context=".MainActivity" >
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_centerInParent="true"
        android:background="#ff0000"
        >
        
        <LinearLayout 
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="70dp"
            android:background="#00ff00"
            ></LinearLayout>
        
        <LinearLayout 
            android:layout_weight="5"
            android:layout_width="0dp"
            android:layout_height="70dp"
            android:background="#0000ff"
            ></LinearLayout>
        
    </LinearLayout>
    
</RelativeLayout>

四、分割线

new一个xml

设置形状,大小,宽度,颜色

使用:设置divider,dividePadding(内边距),showDividers

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line"
    >

    <size 
        android:width="200dp"
        android:height="2dp"
        />
    
    <stroke 
        android:color="#000000"
        />

</shape>
android:divider="@drawable/fg"
android:dividerPadding="2dp"
android:showDividers="middle|end"

五、制作一个页面(登录)

<RelativeLayout 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:background="@drawable/bg_shopping_menu"
    tools:context=".MainActivity" >
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="300dp"
        android:layout_height="70dp"
        android:layout_centerInParent="true"
        >
        
        <LinearLayout 
            android:orientation="vertical"
            android:layout_weight="2"
            android:layout_width="0dp"
            android:layout_height="70dp"
            >
            
            <TextView 
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="账号"
                android:textSize="25dp"
                android:gravity="center"
                
                />
            
            <TextView 
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:text="密码"
                android:textSize="25dp"
                android:gravity="center"
                />
            
        </LinearLayout>
        
        <LinearLayout 
            android:orientation="vertical"
            android:layout_weight="5"
            android:layout_width="0dp"
            android:layout_height="70dp"
            android:divider="@drawable/fg"
            android:dividerPadding="2dp"
            android:showDividers="middle|end"
            >
            
            <EditText  
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                />
            
            <EditText
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                />
            
        </LinearLayout>
        
    </LinearLayout>
    
</RelativeLayout>

 

 

师承上官可编程 —— 陈立臣

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dz小伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值