tags:

views:

1063

answers:

2

How do I go about creating the following layout in Android?

I want a "header", that is, a header that stays the same at all times. The only thing that should change is the area below the header.

Think of it as a webpage, where the content-area is where its all happening =)

+--------------------+
| H E A D E R        |
+--------------------+
|                    |
|                    |
|                    |
|  C O N T E N T     |
|                    |
|                    |
|                    |
+--------------------+

Sure, its easy enough to create a LinearLayot, add a View on the top and then another view below that - tada! But what Im after is how you "set up" or design the project so its easy to just change whats in the Content.

What I really would like is to be able to "swipe" (see here) the area and then just "roll in" a new View/thing in the Content-area, but keep the same header.

What I really miss is a comprehensive library of layoyt-examples...

regards

+5  A: 

You can create a layout file for your header. At the top of the layout for each content activity, include the layout file like:

<include android:id="@+id/header"
         layout="@layout/my_header"
         android:layout_height="wrap_content"
         android:layout_width="fill_parent"/>

How exactly you get the header to stay at the top of the content's layout will vary based on the rest of your layout. You could use a LinearLayout with orientation="vertical", or a relative layout with align_parentTop="true" on your include statement.

This android documentation has a good summary of basic layout types.

Mayra
Thx, I will give that a try =)
Ted
+1  A: 

Another possible solution is using ViewFlipper or ViewSwitcher as the 'Content' section, where you include the various types of content you want to be able to flip between, and just set which view you want to display (you can do animations on flip/switch also). The downside to this is your content has to be added in the main layout, which each view being a child of the ViewFlipper/ViewSwitcher (can use or too, to keep the layouts in separate xml files).

Delegating the rendering of the switched content to another activity is not as straight forward. TabHost/TabWidget does allow that, where the content area of the tab host is generated from another activity. You might be able to use the Tab code as an example if you need to accomplish it that way.

Joe