要想均分布局,必须是在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 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>
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>
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>
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>
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#ff0f00" >
</LinearLayout>
</LinearLayout>
结果如下: