添加滚动在tabhost在安卓tabhost

由网友(不想活又不敢死等数载)分享简介:我有一个选项卡的主机中,我有超过6个按钮。然而,屏幕显示只有3-4按钮。I have a tab host in which i have more than 6 buttons. However the screen shows only 3-4 buttons.下面是我用随图像的code。Following...

我有一个选项卡的主机中,我有超过6个按钮。然而,屏幕显示只有3-4按钮。

I have a tab host in which i have more than 6 buttons. However the screen shows only 3-4 buttons.

下面是我用随图像的code。

Following is the code which i am using along with the image.

<?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="fill_parent"
    android:layout_height="fill_parent"
    android:background="#777777">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"

        >
       <RelativeLayout
            android:id="@+id/layTab"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:background="@drawable/navbar_background"
            android:layout_alignParentBottom="true"
            android:layout_centerVertical="true"
            >
            <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            />
        </RelativeLayout>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/layTab"/>


   </RelativeLayout>
</TabHost>

现在的问题是,我怎么想添加滚动,这样我可以滚动显示高达全部6个按钮或其他任何伎俩。

The question is, How am i suppose to add a scroll so that i can scroll upto all 6 buttons or any other trick.

最好的问候

推荐答案

刚刚巢TabWidget内Horizo​​ntalScrollingView,像这样的:

Just nest the TabWidget inside a HorizontalScrollingView, like this:

<?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="fill_parent"
    android:layout_height="fill_parent"
    android:background="#777777" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <RelativeLayout
            android:id="@+id/layTab"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerVertical="true"
            android:background="@drawable/navbar_background"
            android:gravity="center"
            android:paddingLeft="10dp"
            android:paddingRight="10dp" >

            <HorizontalScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbars="none" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" >
                </TabWidget>
            </HorizontalScrollView>
        </RelativeLayout>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/layTab"
            android:layout_alignParentTop="true" />
    </RelativeLayout>

</TabHost>

顺便说一下,这种解决方案适用于许多其他情况下,RadioGroup中,例如

By the way, this solution works for many other scenarios, RadioGroup, for example

阅读全文

相关推荐

最新文章