Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android的tabhost中添加滚动_Java_Android_Eclipse_Android Layout - Fatal编程技术网

Java 在android的tabhost中添加滚动

Java 在android的tabhost中添加滚动,java,android,eclipse,android-layout,Java,Android,Eclipse,Android Layout,我有一个选项卡主机,其中有6个以上的按钮。但是,屏幕上仅显示3-4个按钮 下面是我与图像一起使用的代码 <?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" an

我有一个选项卡主机,其中有6个以上的按钮。但是,屏幕上仅显示3-4个按钮

下面是我与图像一起使用的代码

<?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个按钮或任何其他技巧


致以最诚挚的问候

只需将TabWidget嵌套在HorizontalScrollingView中,如下所示:

<?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,是的,我做错了。TabWidget需要嵌套。。。我编辑了我的答案。立即尝试是否还需要将HorizontalScrollView嵌套在两个RelativeLayout中?我的嵌套方式是:相对>TabHost>线性>水平>TabWidget,它不会滚动。你认为API自2012年以来是否发生了变化?请为我工作,使用TabHost-LinearLayout。