Search code examples
androidandroid-tabhostviewflipper

Half-screen TabHost


how can I display a Tabhost in the bottom half of the screen, displaying a static picture (can under no circumstances be reloaded/redisplayed each time you swipe).

+--------------------------+---+---+
| =                        | * | ? |   < Action Bar with Help, Settings and 
+--------------------------+---+---+     a sliding drawer from the left
|                                  |     should be present.
|                                  |
|                                  |
|              static              |   < This should, regardless of the tab 
|           picture/map            |   < selected, be the same.
|                                  |
|                                  |
|                                  |
+----------------------------------+
| TAB1 | TAB2 | TAB3 | TAB4 | TAB5 |   < There will be about 20 Tabs, if
+----------------------------------+     that is of any relevance
|                                  |
|     TEXTTEXTTEXTTEXTTEXTTEXT     |   < Only the Text should, depending on 
|     TEXTTEXTTEXTTEXTTEXTTEXT     |   < the selected Tab, be switched
|     TEXTTEXTTEXTTEXTTEXTTEXT     |   < accordingly.
|     TEXTTEXTTEXTTEXTTEXTTEXT     |
|                                  |
+----------------------------------+

If this is not possible, what can I use? I've head of TextSwitcher, but that doesn't really have the nice continous swipe animation of the tabHost.

Thanks a lot.


Solution

  • One way to do this would be to have two vertically positioned Fragments in your Activity as follows:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
    <fragment android:name="com.whatever.ImageFragment"
              android:id="@+id/image_fragment"
              android:layout_weight="1"
              android:layout_height="0dp"
              android:layout_width="match_parent" />
    
    <fragment android:name="com.whatever.TabHostFragment"
              android:id="@+id/tabhost_fragment"
              android:layout_weight="2"
              android:layout_height="0dp"
              android:layout_width="match_parent" />
    
    </LinearLayout>
    

    The top Fragment would hold the MapView or ImageView, and the bottom fragment would contain the FragmentTabHost with the text Fragments. Note that in this case the FragmentTabHost would be forced to use the getChildFragmentManager() method to get the text Fragments.