美文网首页
LinearLayout中的weight以及设置分割线

LinearLayout中的weight以及设置分割线

作者: 小星star | 来源:发表于2019-01-21 15:35 被阅读2次

    参考地址:
    http://www.runoob.com/w3cnote/android-tutorial-linearlayout.html

    一、weight
    weight 用于 LinearLayout中的 比例划分
    水平方向1:3划分


    image.png
    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:background="@color/blue">
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:background="@color/green"/>
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="3"
                android:layout_height="match_parent"
                android:background="@color/prue"/>
        </LinearLayout>
    
    </android.support.constraint.ConstraintLayout>
    

    注意这里 LinearLayout 的 android:orientation="horizontal",这样才能使得水平方向分割。

    用法归纳: 按比例划分水平方向:将涉及到的View的android:width属性设置为0dp,然后设置为android weight属性设置比例即可;类推,竖直方向,只需设android:height为0dp,然后设weight属性即可! 大家可以自己写个竖直方向的等比例划分的体验下简单用法!

    二、为LinearLayout设置分割线
    两种方法:

    1. 直接在布局中添加一个view
    <View  
        android:layout_width="match_parent"  
        android:layout_height="1px"  
        android:background="#000000" />  
    
    1. 使用LinearLayout的divider属性
      直接为LinearLayout设置分割线 这里就需要你自己准备一张线的图片了 1)android:divider设置作为分割线的图片 2)android:showDividers设置分割线的位置,none(无),beginning(开始),end(结束),middle(每两个组件间) 3)dividerPadding设置分割线的Padding

    相关文章

      网友评论

          本文标题:LinearLayout中的weight以及设置分割线

          本文链接:https://www.haomeiwen.com/subject/qgucjqtx.html