2

タブの下にタブを配置したい。基本的に、Tab1とTab2という親タブがあります。Tab1の下に、Tab1aとTab1b、およびTab2の下に同様に2つのタブの2つのタブが必要です。私は次のxmlファイル構造を持っています:

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabHost"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

<TabWidget 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"
android:tabStripEnabled="false"     
android:background="@drawable/tabwstyle"/>

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabcontent">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:paddingTop="60dp"
    android:id="@+id/tab1">     

    <TabHost 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tabHost_pb">

        <TabWidget 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@android:id/tabs"
            android:tabStripEnabled="false"     
            android:background="@drawable/tabwstyle"/>

        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" 
            android:paddingTop="60dp"
            android:id="@+id/tab1a">


                <FrameLayout 
                    android:id="@+id/frame1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                <ListView
                    android:id="@+id/listview"
                    android:layout_width="fill_parent"    
                    android:layout_height="wrap_content" 
                    android:divider="@drawable/divider"
                    android:dividerHeight="10dp" 
                    android:paddingTop="15dp"
                    android:smoothScrollbar="true"/>

                </FrameLayout>

                <FrameLayout 
                    android:id="@+id/frame2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:visibility="gone">
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:text="@string/testtxt"
                    android:id="@+id/frame2text"/>
                </FrameLayout>

        </LinearLayout>    


        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:paddingTop="60dp"
            android:id="@+id/tab1b">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:text="@string/testtxt"
                android:id="@+id/tab1btext"/>

        </LinearLayout>

    </TabHost>


</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingTop="60dp"
    android:id="@+id/tab2">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:text="@string/testtxt"
        android:id="@+id/tab2text"/>

</LinearLayout>

 </FrameLayout>
 </TabHost>

仕事をしたい私のJavaコード:

 TabHost tabhost=(TabHost) findViewById(R.id.tabHost);
    tabhost.setup();                     

    tabhost.getTabWidget().setDividerDrawable(R.drawable.divider2);             

    TabSpec spec1=tabhost.newTabSpec("Tab 1");
    spec1.setContent(R.id.tab1);
    spec1.setIndicator("Pain Box");

    TabSpec spec2=tabhost.newTabSpec("Tab 2");
    spec2.setIndicator("Pain List");
    spec2.setContent(R.id.tab2);

    tabhost.addTab(spec1);
    tabhost.addTab(spec2);             

    //Keep below after Add spec or crash 
    tabhost.getTabWidget().getChildTabViewAt(0).setBackgroundDrawable(null);
    tabhost.getTabWidget().getChildTabViewAt(1).setBackgroundDrawable(null);

    TabHost tabhost_pb=(TabHost) findViewById(R.id.tabHost_pb);
    tabhost_pb.setup();

    tabhost_pb.getTabWidget().setDividerDrawable(R.drawable.divider2);

    TabSpec spec_pb1=tabhost_pb.newTabSpec("Tab1a");
    spec_pb1.setContent(R.id.tab1a);
    spec_pb1.setIndicator("All");

    TabSpec spec_pb2=tabhost_pb.newTabSpec("Tab1b");
    spec_pb2.setContent(R.id.tab1b);
    spec_pb2.setIndicator("Followers");

    tabhost_pb.addTab(spec_pb1);
    tabhost_pb.addTab(spec_pb2);

    tabhost_pb.getTabWidget().getChildTabViewAt(0).setBackgroundDrawable(null);
    tabhost_pb.getTabWidget().getChildTabViewAt(1).setBackgroundDrawable(null);

最初のタブの下のすべての部分をコメントすると、コードは正常に機能します。から始まるすべての行にコメントを付けます: TabHost tabhost_pb=(TabHost) findViewById(R.id.tabHost_pb);

したがって、コメントすると、タブはTab1の下にレンダリングされませんが、スペースが残ります

4

1 に答える 1

2

Stackoverflowに投稿されたネストされたタブについて同様の問題があります..ここにリンクがあります..これが役立つかもしれません。

于 2012-11-22T01:44:13.827 に答える