2012-11-22 94 views
2

我想将选项卡放在选项卡下。基本上我有一个家长标签说Tab1和Tab2。在Tab1下,我需要2个更多的选项卡:Tab1a和Tab1b,以及Tab2下面的类似2个选项卡。我有下面的XML文件结构:在Android中的选项卡下有选项卡

<?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的arent下显现,但他们留下的空间

+0

您使用的是哪个版本的android sdk? – Dilberted

+0

即时通讯使用sdk 8,android 2.2 – Brooklyn

回答

2

有一个类似的问题有关发布#2 .. Here is the link。5月嵌套的标签这可能会有所帮助。

+0

他正在创建一个新的活动被调用,并没有定义。我实际上没有定义一个新的活动。我只想与这项活动合作 – Brooklyn

相关问题