Reputation: 2625
I'm desiring to create this type of layout....
One static fragment created in xml on the left side
One static fragment created in xml on the bottom as a footer
One static fragment created in xml on the top as a header
and finally
One container for different dynamic fragments created @ runtime based on different broadcast from outside to the activity.
here's a visual....
How can i structure this activity's layout in xml?
Upvotes: 0
Views: 2486
Reputation: 14710
Use a RelativeLayout
to place top and bottom fragments, then in between add a horizontal LinearLayout
containing List fragment and last dynamic fragment. The dimensions of the fragments can be put in dimens
file, I have hardcoded 48
dp in xml; also the list area takes 20% of the width, while the content area takes the rest. Here's something to get you started with:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/top_fragment"
android:name="com.adip.sampler.fragments.TopFragment"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/bottom_fragment"
android:name="com.adip.sampler.fragments.BottomFragment"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_fragment"
android:layout_below="@+id/top_fragment"
android:baselineAligned="false"
android:orientation="horizontal" >
<fragment
android:id="@+id/list_fragment"
name="com.adip.sampler.fragments.ListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/dynamic_area"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" >
</FrameLayout>
</LinearLayout>
</RelativeLayout>
or if you want to have only viewgroups and no fragment
tags you could have this layout (You can use any ViewGroup
instead of FrameLayout
, I am using it for efficiency reasons):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/top_fragment"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@+id/bottom_fragment"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_alignParentBottom="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_fragment"
android:layout_below="@+id/top_fragment"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/list_fragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/dynamic_area"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" >
</FrameLayout>
</LinearLayout>
</RelativeLayout>
Upvotes: 1