Search code examples
androidandroid-layoutandroid-fragmentsandroid-tabhostandroid-view

Adjusting layout sizes, height and with inside fragment classes


We are trying to have a Tabwidget to the right of the screen in vertical direction. But have a problem with resizing tabs to length of the layout containing the tabs.

Also we cant find a way to get sizes from views and layouts inside the fragment code.

XML and graphical layout view is attached below.

 <?xml version="1.0" encoding="utf-8"?>
 <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            >
        <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >
            <LinearLayout
                    android:id="@+id/all"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    >
                <ListView
                        android:id="@+id/listView1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:clipToPadding="false" >
                </ListView>
            </LinearLayout>
            <LinearLayout
                    android:id="@+id/record"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     >
                <TextView
                        android:id="@+id/tabtxt2"
                        android:layout_width="wrap_content"
                        android:layout_height="80dp"
                        android:layout_gravity="center_horizontal"
                        android:text="Tab 2 Content Jehaw!" >
                </TextView>
                <ImageView android:id="@+id/journal_image"
                           android:contentDescription="Journal"
                           android:src="@drawable/ic_launcher"
                           android:layout_width="wrap_content"
                           android:layout_height="wrap_content"
                           android:layout_gravity="center_horizontal|center_vertical" >
                </ImageView>
            </LinearLayout>
            <LinearLayout
                    android:id="@+id/history"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                     >
                <TextView
                        android:id="@+id/tabtxt3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal"
                        android:text="Tab 3 Content Jehaw!" >
                </TextView>
            </LinearLayout>
        </FrameLayout>

    <LinearLayout android:id="@+id/tabs_layout"
                  android:layout_width="100dip"
                  android:layout_height="match_parent"
                  android:layout_weight="1" >
        <TabWidget android:id="@android:id/tabs"
                   android:layout_height="match_parent"
                   android:layout_width="wrap_content"
                   android:divider="@color/green"
                   android:rotation="90"
                   android:layout_gravity="center_vertical"
                >
        </TabWidget>
    </LinearLayout>
    </LinearLayout>
</TabHost>

Layout
Size of tabs should stretch to fill all the white area(Layout) in vertical direction


Solution

  • TabWidget has hardcoded setOrientation(LinearLayout.HORIZONTAL); in TabWidget init() method and TabHost does not support the orientation attribute and tabs can only be used horizontally.