【发布时间】:2013-07-04 11:18:00
【问题描述】:
我正在尝试让我的scrollable tab 工作(类似于 Google Play 中的菜单的滚动标签)。我使用android.support.v4.app.FragmentTabHost 作为标签主机,android.support.v4.app.Fragment 作为片段。除了选项卡主机不可滚动(我使用HorizontalScrollView 用于滚动功能)之外,一切正常。如果我将 tabhost 更改为标准 android.widget.TabHost 并将活动更改为 TabActivity,那么它可以工作。因此,我假设 FragmentTabHost 的某些东西使 ScrollView 无法正常工作。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
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" >
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="horizontal">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
这是 FragmentTabHost 的一些代码:
public class MyTabActivity extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(
mTabHost.newTabSpec("tab1").setIndicator("Tab 1",
getResources().getDrawable(android.R.drawable.star_on)),
FragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("tab2").setIndicator("Tab 2",
getResources().getDrawable(android.R.drawable.star_on)),
FragmentTab.class, null);
mTabHost.addTab(
mTabHost.newTabSpec("tab3").setIndicator("Tab 3",
getResources().getDrawable(android.R.drawable.star_on)),
FragmentTab.class, null);
......
......
如果我添加更多选项卡,选项卡会变得更小以适应屏幕。滚动条永远不会出现,但我希望它可以滚动!
怎么了?
【问题讨论】:
-
您引用的是
ViewPager和PagerTitleStrip而不是FragmentTabHost。 -
不是
ViewPager用于滑动整个屏幕吗?还是可以用ViewPager滑动屏幕的一部分? -
您可以使用 ViewPager 滚动整个内容视图或其中的一部分。 developer.android.com/training/animation/screen-slide.html
标签: android android-fragments android-tabactivity android-scrollbar