我在前段時間寫的一些代碼中有這樣的例子。
我需要的也是一個選項卡內的列表。所以這個驅動程序是其中有其他活動的選項卡。將具有ListActivity Intent的TabSpec添加到TabHost。
這是選項卡的佈局:
<?xml version="1.0" encoding="utf-8"?>
<TabHost 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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
那麼這就是在標籤列表視圖中的一個佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/no_items"/>
</LinearLayout>
這是對標籤本身的代碼:
公共類
MyTabActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_tabs);
Bundle bundle = getIntent().getExtras();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, MyListActivity.class);
spec = tabHost .newTabSpec("some_things")
.setIndicator("Some")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MyOtherActivity.class);
spec = tabHost .newTabSpec("top_things")
.setIndicator("Top")
.setContent(intent);
tabHost.addTab(spec);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 35;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 35;
}
}
在這種情況下,您應該使用ActivityGroup而不是Activity,然後在單個選項卡中添加活動組,以便一次控制多個活動。 – DynamicMind 2011-06-13 11:41:32
嗨動態的心態,謝謝!我認爲它是一個很好的探索點,如果你有任何好的教程來了解更多關於如何使用它的信息,那會好嗎?我知道我總是可以谷歌,但你有什麼好的ActivityGroup教程的個人建議? – jamen 2011-06-14 11:45:27