我想要有不同数量的选项卡,并且我正在使用TabHost。 取决于数据,这些可能在1到8之间。带水平滚动的TabHost问题
我想添加水平滚动,以便当所有8个都在那里时,它看起来不会过于拥挤。
问题是当5个或更多有它看起来很好,滚动的作品! 但是,当标签数量少,我看到空白。标签不会被拉伸以填充额外的空间。
我该如何解决这个问题? 这可以通过Java代码完成吗?
这里是我的布局XML ...
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!---Other Views--->
<HorizontalScrollView
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>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
TabActivity和TabHost在android中被删除。你可以使用'ListFragment'而不是'TabActvity'。查看[这里](http://v4all123.blogspot.com/2013/04/fragments-in-android.html)简单的'ListFragment'教程。 – Gunaseelan 2013-04-26 10:17:37
使用版本2.3,所以我可以使用它 – 2013-04-26 11:37:47
是的。您可以使用。但是为什么'tabhost'被depricated在使用它时,你的活动可能会运行缓慢。那就是问题所在。 – Gunaseelan 2013-04-26 11:50:47