【发布时间】:2012-11-22 18:11:15
【问题描述】:
我目前正在开发我的第一个 android 应用程序。我正在为我的应用程序使用选项卡式布局。我按照开发指南上的教程进行操作,但遇到了问题。本教程只使用了三个选项卡,但我需要更多。因此,标签会调整大小并聚集在一起。我希望有人能告诉我如何让它们滚动,就像在海豚浏览器中使用多个标签时一样。谢谢!
~亚伦
【问题讨论】:
我目前正在开发我的第一个 android 应用程序。我正在为我的应用程序使用选项卡式布局。我按照开发指南上的教程进行操作,但遇到了问题。本教程只使用了三个选项卡,但我需要更多。因此,标签会调整大小并聚集在一起。我希望有人能告诉我如何让它们滚动,就像在海豚浏览器中使用多个标签时一样。谢谢!
~亚伦
【问题讨论】:
使用 Yoel 所说的,只需添加:
android:fillViewport="true 和
android:scrollbars="none"
到 HorizontalScrollView 像这样:
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
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="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
【讨论】:
我建议改为使用 HotizontalScrollView 包装 TabWidget。这样,您仍然可以按原样使用选项卡。
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</HorizontalScrollView>
请务必注意,如果您使用较少的选项卡,这将导致选项卡不会填满屏幕的整个宽度。我目前正在寻找解决此问题的方法。
【讨论】:
在这种情况下,您可能不想使用制表符。相反,您可以将所有“选项卡”放入屏幕顶部的水平线性布局中,像这样包裹在 ScrollView 中
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout
android:orientation="horizontal" android:layout_height="wrap_content"
android:layout_width="fill_parent">
...buttons go here...
</LinearLayout>
</HorizontalScrollView>
我认为这将为您提供所需的结果,但请告诉我
【讨论】: