<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上,就会把其中的文字显示在居中的位置,