Reputation: 87
I've got my LinearLayout part of my app complete. I'm now adding a small bar at the top of the screen/activity using RelativeLayout, but I seem to have it backwards of the way I want it in the picture below.
The tan-colored Linear Layout is visible in a small bar at the top, which is what I want the white RelativeLayout to be and the LinearLayout should be using the white space that RelativeLayout's taking up. I'm confused as how to:
change RelativeLayout so that it's height is only as tall as the bar on the top (50dp)
have LinearLayout begin 50dp down, so that it's top meets the bottom of the RelativeLayout
Original XML file containing only LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#F8FBBF" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
Modified XML file where RelativeLayout encompasses the LinearLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#F8FBBF" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
</RelativeLayout>
Thanks for any help offered in advance.
Upvotes: 1
Views: 12240
Reputation: 1159
You could do something like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp" >
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#F8FBBF" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
</LinearLayout>
But that introduces nested layouts. You could get by with:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#F8FBBF"
android:layout_margintop"50dip" >
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:cacheColorHint="#00000000"/>
</LinearLayout>
</RelativeLayout>
Just adding a margintop to the linear layout
Upvotes: 2