layout_weight,divider,shape[line]



layout_weight:父LinearLayout和两个子View的layout_width的不同选择导致不同比例(4种)

1、 当父LinearLayout的android:layout_width = "match_parent"时,三种。

1、若两个子view,layout_width = "match_parent",layout_weight = 1,2
则真实宽度比为2,1
2、若两个子view,layout_width = "wrap_content",layout_weight = 1,2
则真实宽度比为1,2
3、若两个子view,layout_width = "0dp",layout_weight = 1,2
则真实宽度比为1,2

详见点击打开链接

2、当父LinearLayout的android:width = "wrap_content"时,一种。

若两个子View的layout_weight的值分别为1,2,此时不管这两个子View的layout_width设置为wrap_content,match_parent或"0dp",这两个 子View的真实宽度比都是2:1。

divider

Linearlayout属性的设置

        android:showDividers="middle"
        android:divider="@drawable/divider_line_vertical"
        android:dividerPadding = "2dp"

android:showDividers = "middle|end|beginning|none"

middle 在每一项中间添加分割线,end 在整体的最后一项添加分割线,beginning 在整体的最上方添加分割线,none 无

divider的值要为drawable id

dividerPadding为内边距,上例中即为垂直方向上,LinearLayout与竖线上下两头的距离

上例的完整代码

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

    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="@android:color/darker_gray"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:showDividers="middle"
        android:divider="@drawable/divider_line_vertical"
        android:dividerPadding = "4dp">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/rexiao"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_weight="1"
            android:showDividers="middle"
            android:divider="@drawable/divider_line_horizontal"
            android:dividerPadding = "4dp">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/haohuo" />
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/xinping" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>


divider_line_vertical.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@android:color/darker_gray" />

    <size
        android:height="100dp"
        android:width="1dp" />

</shape>



divider_line_horizontal.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@android:color/darker_gray" />

    <size
        android:height="1dp"
        android:width="100dp" />

</shape>

shape[line]


为水平方向上,且match_parent,以上画分割线用rectangle更好



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值