Android 如何设置选项卡主机的滚动条
我想在选项卡主机中设置滚动条。在选项卡中有五个选项卡,但我只想显示三个 标签在一个时间和如何使滚动条,以便标签可以滚动更多的标签…请为我提供一些解决方案 这是一个xml文件Android 如何设置选项卡主机的滚动条,android,tabs,scroll,android-tabhost,Android,Tabs,Scroll,Android Tabhost,我想在选项卡主机中设置滚动条。在选项卡中有五个选项卡,但我只想显示三个 标签在一个时间和如何使滚动条,以便标签可以滚动更多的标签…请为我提供一些解决方案 这是一个xml文件 <RelativeLayout android:id="@+id/rl3" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TabHost android:
<RelativeLayout
android:id="@+id/rl3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/gray" >
<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:gravity="center" >
<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="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<fragment
android:id="@+id/fragment1"
android:name="info.tech.slidermenu.Home_feed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="@+id/fragment2"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="@+id/fragment3"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="@+id/fragment4"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="@+id/fragment5"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
截屏
您已经在为
选项卡小部件
使用水平滚动视图
,因此这是正确的方法。如果你不能在这样做的情况下进行scrool,那么很可能你遇到了布局问题
您没有详细说明是否为TabWidget
使用自定义布局,但如果没有,这将是实现所需的一个好方法,因为没有一种方法可以说“我一次只想显示3个选项卡”
只需为选项卡定义一个新的布局,使三个选项卡一起适应屏幕的宽度,其余选项卡可以通过滚动访问
----编辑---
我在您的代码中几乎看到了LinearLayout
s。试着这样做:
<LinearLayout
android:id="@+id/TabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="99"
android:orientation="vertical">
<TabHost
android:id="@+android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/TabLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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>
<FrameLayout
android:id="@+android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
如果您的代码没有走远。我建议使用带有PageStrip的查看寻呼机。它们通过翻转屏幕来提供滚动,另外它还使用片段,TabHost也不推荐使用。你肯定会得到更多的例子。只是谷歌而已。:)你能帮我如何使用这段代码吗?请实现一个fragmentTab,你正在使用的代码在你进步后会感觉不太好。对于片段,您不必担心屏幕大小,您的选项卡将自动调整。您似乎有一个水平滚动视图
环绕在选项卡小部件
,这是使用选项卡主机
滚动选项卡的典型方法。请完整准确地解释您的问题所在。@Commonware选项卡根本不可见。…只有片段内容可见…如果我不使用horizontalscrollview…所有选项卡都可见。。
<LinearLayout
android:id="@+id/TabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="99"
android:orientation="vertical">
<TabHost
android:id="@+android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/TabLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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>
<FrameLayout
android:id="@+android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
</TabHost>
</LinearLayout>