【Android Studio】 LinearLayout

线性布局

排列方式

android:orientation="vertical"    垂直排列

android:orientation="horizontal"    水平排列(不写时默认为此) 

对齐

android:gravity="center|bottom"    组件所包含的子元素的对齐方式,可多个组合

android:layout_gravity="center_horizontal"    控制该组件在父容器里的对齐方式

    <LinearLayout
        android:background="@color/teal_700"
        android:layout_gravity="center_horizontal"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

    <LinearLayout
        android:background="@color/purple_200"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

    <LinearLayout
        android:background="@color/teal_200"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

分割线

android:divider="@drawable/mouse"    设置分割线

android:showDividers="middle"    设置分割线所在位置(none无、beginning开始、end结束、middle每两个组件之间)

android:dividerPadding="15dp"    设置分割线的padding,只有左右

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:divider="@drawable/mouse"
    android:showDividers="middle"
    android:dividerPadding="15dp">

    <TextView
        android:id="@+id/tv"
        android:textSize="30sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <LinearLayout
        android:background="@color/purple_200"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

    <LinearLayout
        android:background="@color/purple_500"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

    <LinearLayout
        android:background="@color/purple_700"
        android:layout_width="100dp"
        android:layout_height="100dp"/>

</LinearLayout>

分割线另一种做法

    <LinearLayout
        android:layout_weight="1"
        android:background="@color/teal_700"
        android:layout_gravity="center_horizontal"
        android:layout_width="100dp"
        android:layout_height="0dp"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="5dp"
            android:background="@color/red"/>

    <LinearLayout
        android:layout_weight="2"
        android:background="@color/purple_200"
        android:layout_width="100dp"
        android:layout_height="0dp"/>

    <LinearLayout
        android:background="@color/teal_200"
        android:layout_width="100dp"
        android:layout_height="0dp"/>

权重

android:layout_weight="1"    该属性是用来等比例的划分区域,分配的是剩余空间,组件高度、宽度为match_parent时会有问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值