添加滚动在tabhost在安卓 [英] Adding scroll in tabhost in android

查看:95
本文介绍了添加滚动在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 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

这篇关于添加滚动在tabhost在安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆