线性布局——大色块

Hello大家好,让我们今天来实现一个大色块的设计~~比如说,像酱紫的,是的,我就是这样一个喜欢很明媚颜色的女纸。

线性布局里,开始最让我绕的就是vertical和horizonal属性,vertical表示一块一块垂直排列,horizonal表示一块一块水平排列。因此,我们一下子就可以看出来,上半部分是horizonal属性,下半部分是vertical属性。

第一个知识点是平均分的实现,上半部分在水平方向上平均分,那么weight属性置为1,width属性置为0;下半部分在垂直方向上平均分,则weight属性置为1,height属性置为0,其实这个很好记,如果在水平方向上平均分,那么它的宽度由1:1:1这样的比例决定,而不是具体的数值。

第二个知识点是颜色的选取,我们需要在values-->colors.xml中添加颜色,并在linear.xml中使用。

第三个就是实现的逻辑了,首先,最外面的大框是一个LinearLayout,它分为上下两个部分,所以属性为vertical.在这个大框下,再建立两个LinearLayout,上半部分为horizonal,下半部分为vertical.里面的设计就是平均分的设计了

 

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:background="@color/colorAccent"
            android:layout_height="match_parent" />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:background="@color/purple"
            android:layout_height="match_parent" />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:background="@color/purple2"
            android:layout_height="match_parent" />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:background="@color/blue"
            android:layout_height="match_parent" />

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp">

        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:background="@color/yellow"
            android:layout_height="0dp" />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:background="@color/orange"
            android:layout_height="0dp" />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:background="@color/red"
            android:layout_height="0dp" />
        <TextView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:background="@color/brown"
            android:layout_height="0dp" />

    </LinearLayout>

</LinearLayout>

显示结果:

 

喜欢就点个赞哦 么么哒~

 

《原创·创世纪》

 

转载于:https://www.cnblogs.com/soada/p/5689730.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值