我想將選項卡放在選項卡下。基本上我有一個家長標籤說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下顯現,但他們留下的空間
您使用的是哪個版本的android sdk? – Dilberted
即時通訊使用sdk 8,android 2.2 – Brooklyn