eclipse 在android中的tabhost中添加滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11904806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding scroll in tabhost in android
提问by Muhammad Umar
I have a tab host in which i have more than 6 buttons. However the screen shows only 3-4 buttons.
我有一个标签主机,其中有 6 个以上的按钮。但是屏幕只显示 3-4 个按钮。
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>
The question is, How am i suppose to add a scroll so that i can scroll upto all 6 buttons or any other trick.
问题是,我应该如何添加滚动条,以便我可以滚动到所有 6 个按钮或任何其他技巧。
Best Regards
此致
回答by Android Joker
Just nest the TabWidget inside a HorizontalScrollingView, like this:
只需将 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>
By the way, this solution works for many other scenarios, RadioGroup, for example
顺便说一句,这个解决方案适用于许多其他场景,例如 RadioGroup