2

スクロール可能なタブを機能させようとしています (Google Play のメニューのようなスクロール タブ)。android.support.v4.app.FragmentTabHostタブホストおよびandroid.support.v4.app.Fragmentフラグメントとして使用しています。タブホストがスクロールできないことを除いて、すべてが機能します(HorizontalScrollViewスクロール機能に a を使用しています)。タブホストを標準に変更し、アクティビティを に変更する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 に答える