我正在编写一个使用许多片段的应用程序。我使用过 ActionBarSherlock(带有 ActionBar)。为了解决错误 # 240,我决定切换一个功能正常的实现以将 ActionBarSherlock 与TabHost一起使用。经过半个小时的工作,它工作正常,除了当我在页面之间滑动时:选择了对应的选项卡,但没有居中并且通常甚至不可见,因此用户无法看到选择了哪个选项卡。
在图片中,您可以看到可见片段(“WEEKLY S..”),但选项卡只有一半可见。下一次滑动只会使“WEEKLY S...”看起来像“CALENDAR EVENTS”,除非我手动滑动 TabWidget,否则我不知道选择了哪个选项卡。
这是我的activity_main.xml:
<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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
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"
android:tabStripEnabled="true"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
我的 TabsAdapter 与Jake Wharton的FragmentTabsPager示例相同。
欢迎任何建议!