Android 如何在TabView中实现ListView?
我有一个关于在选项卡布局中实现Android 如何在TabView中实现ListView?,android,listview,android-layout,Android,Listview,Android Layout,我有一个关于在选项卡布局中实现ListView布局的问题 当我们在下面有一个自定义标题栏,下面是一个选项卡布局,每个选项卡布局内是一个列表视图时,主要活动应该是ListView的扩展还是选项卡视图的扩展?它可以是列表视图吗 原因是我创建了一个功能正常的列表视图,我想通过使用列表作为模板并添加选项卡(类别)来扩展它,这些选项卡(类别)可以分支到更多这样的列表中。我使用ListView完成了这项工作,似乎添加选项卡需要通过扩展tabview来重写整个代码。在实现我的选项卡时,有什么方法可以利用Lis
ListView
布局的问题
当我们在下面有一个自定义标题栏,下面是一个选项卡布局,每个选项卡布局内是一个列表视图时,主要活动应该是ListView
的扩展还是选项卡视图的扩展?它可以是列表视图吗
原因是我创建了一个功能正常的列表视图
,我想通过使用列表作为模板并添加选项卡(类别)来扩展它,这些选项卡(类别)可以分支到更多这样的列表中。我使用ListView
完成了这项工作,似乎添加选项卡需要通过扩展tabview
来重写整个代码。在实现我的选项卡时,有什么方法可以利用ListView
我注意到没有关于如何同时实现这两个视图/布局的教程,有人有任何链接和说明吗 我刚才写的一些代码中有一个例子 我需要的也是一个标签内的列表。因此,这个驱动程序是包含其他活动的选项卡。将具有ListActivity意图的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>
我在不久前写的一些代码中有一个这样的例子 我需要的也是一个标签内的列表。因此,这个驱动程序是包含其他活动的选项卡。将具有ListActivity意图的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>
在这种情况下,您应该使用ActivityGroup而不是Activity,并在单个选项卡中添加Activity group。Activity group一次可以控制多个活动。您好,Dynamic mind,谢谢!我认为这是一个很好的探索点,如果你有任何好的教程来了解更多关于如何使用它的内容,那会好吗?我知道我可以用谷歌搜索,但你对ActivityGroup教程有什么好的个人建议吗?在这种情况下,你应该使用ActivityGroup而不是Activity,并在单个选项卡中添加Activity group。Activity group一次可以控制多个活动。嗨,Dynamic mind,谢谢!我认为这是一个很好的探索点,如果你有任何好的教程来了解更多关于如何使用它的内容,那会好吗?我知道我可以用谷歌搜索,但你对活动小组教程有什么好的个人推荐吗?嗨,瑞秋,谢谢!我会假设在每个选项卡中都有一个listactivity,它会将每个选项卡填充到各自的列表中?是的,您可以在TabActivity java代码中将ListActivities添加到TabHost中,这些ListActivities控制它们显示的列表。TabActivity只知道应该在每个窗格中显示什么,ListActivities知道应该在列表中显示什么。嗨,rachel,谢谢!我会假设在每个选项卡中都有一个listactivity,它会将每个选项卡填充到各自的列表中?是的,您可以在TabActivity java代码中将ListActivities添加到TabHost中,这些ListActivities控制它们显示的列表。TabActivity只知道应该在每个窗格中显示什么,ListActivities知道应该在列表中显示什么。
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;
}
}