Android XML视图 平分效果

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:baselineAligned="false"
        <span style="color:#FF0000;">android:minHeight="30dp"</span>
        android:orientation="horizontal" >

        <LinearLayout
            <span style="color:#FF0000;">android:layout_width="0dip"</span>
            android:layout_height="match_parent"
            <span style="color:#FF0000;">android:layout_weight="1"</span>
            android:background="@color/green" >

            <TextView
                android:id="@+id/textView13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="sadfsdfdfs"
                <span style="color:#FF0000;">android:visibility="gone"</span> />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/red" >

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="sadfsdfdfs"
                android:visibility="gone" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/blue"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
               <span style="color:#CC33CC;"> android:layout_gravity="center"</span>
                android:text="sadfsdfdfs"
                android:visibility="visible" />
        </LinearLayout>
    </LinearLayout>

以上显示了三个LinearLayout,三等平分界面水平方向。


注意上面的红色标注的属性,如果不设置的话,那么达不到效果,

效果:当父ViewGroup中的视图被设置为gone的时候依旧能够平分布局,如果任何一个不设置,那么达不到效果

如果: android:layout_width="0dip"设置成 android:layout_width="wrap_parent"那么当子视图大于平分的宽度的时候,就会溢出,比例就达不到了。

如果: android:minHeight="30dp"不设置,那么当子视图被设为gone的时候将在页面上占用空间。


同时注意:android:layout_gravity="center"的设置的位置:layout_gravity表示当前布局居中,例如:设置在LinearLayout上,那么LinearLayout就会居中显示而不是其中的子视图居中显示,相对应的android:lgravity="center"表明当前视图的子视图居中显示,例如:设置在TextView上,那么不会起到效果,如果设置到Button上,就会把其中的文字显示在居中的位置,


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值