我在前段时间写的一些代码中有这样的例子。
我需要的也是一个选项卡内的列表。所以这个驱动程序是其中有其他活动的选项卡。将具有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