android中多个LinearLayout平分布局

来源:互联网 发布:海淘网转运 知乎 编辑:程序博客网 时间:2024/04/29 18:27
要想均分布局,必须是在LinearLayout布局下才可完成,其他文章中都是在LinearLayout中均分控件,现在是将LinearLayout中嵌套多个LinearLayout,均分LinearLayout,这样你就可以在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="match_parent"
    android:layout_gravity="center"
    android:orientation="horizontal" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#ff00f0" >
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#f0f00f" >
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#0000ff" >
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:background="#ff0f00" >
    </LinearLayout>
</LinearLayout>

结果如下:



1 0
原创粉丝点击