2

我正在尝试让我的可滚动选项卡工作(类似于 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);
    ......
    ......

如果我添加更多选项卡,选项卡会变得更小以适应屏幕。滚动永远不会出现,但我希望它可以滚动!

怎么了?

4

1 回答 1

0

使用 Viewpager 是个好主意...但是...如果您想继续使用此实现,请考虑此 XML 布局。

 <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="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"/>
        </HorizontalScrollView>
于 2015-08-28T06:35:39.937 回答