Search code examples
androidandroid-tabhostvertical-alignment

Android Vertical tabhost


i want to built a vertical Tab host like the below image

enter image description here

i tried with the following code but the tabs are not visible

getTabWidget().setOrientation(LinearLayout.VERTICAL);

is it possible to implement tab host like below.if possible tell me the way to implement tab host like below.and also post the links if there are any built in project's to implement it like the below Image. (or) is it possible to add an activity to image view click similar to tab bar click like below

  mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1)); 

because if it is possible i will put image views and change the activities on each item click

Help me out in making the vertical tab-host.


Solution

  • You just need to place your tab Widget in a horizontal LinearLayout in your XML file:

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/imageView3" >
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>
    
            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1" >
            </android.support.v4.view.ViewPager>
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_gravity="center_vertical">
            </TabWidget>
    
        </LinearLayout>
    </TabHost>
    

    this will place the tabs to the right of the content, if you want it to the left you need to rearrange the order in the XML file.