Nesting layouts
This layout for some reason doesn't work as expected. The two text boxes are overlapping, despite the fact that I'm using the layout_below tag. What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"&开发者_如何学Cgt;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/homeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dashboard" />
</LinearLayout>
<RelativeLayout android:id="@+id/dashboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/actionbar">
<TextView android:id="@+id/libraryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dashboard Area" />
</RelativeLayout>
</LinearLayout>
Sure it does not ... You have to enclose both layouts in a parent layout eg.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
...
android:orientation="vertical"
/>
<LinearLayout
...
>
</LinearLayout>
<RelativeLayout
...
>
</RelativeLayout>
</LinearLayout>
It might however be better to use RelativeLayout and arrange the views using parameters provided.
精彩评论