在我不知道这个属性之前,底部菜单栏的布局需要写RelativeLayout来完成,但是,在我知道之后,妈妈再也不让我用RelativeLayout了。
接下来,先认识下android:clipChildren这个属性:是否限制子View在其范围内,默认为true,在这里,我们需要把他设置为false。
先看下用了这个属性之后,实现这个布局的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:clipChildren="false"
android:gravity="bottom"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="TextView" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#234221"
android:gravity="bottom" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_gravity="bottom"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
是不是
感觉很惊讶,不用什么RelativeLayout布局,也不用重叠,简单的LinearLayout就可以轻松实现.只需以下步骤:
1、只需在根节点设置android:clipChildren为false即可,默认为true(经过测试,其实是在他爹的爹设置,也就是他爷爷节点设置)
2、可以通过android:layout_gravity控制超出的部分如何显示。