我对选项卡布局中ListView
布局的实现有疑问。
当我们实现这个时,我们在其下面有一个自定义标题栏,它是一个标签布局,每个标签布局中都是一个列表视图,主要活动应该是ListView
的扩展还是扩展名? Tab View?它可以是列表视图吗?
原因是我已经创建了ListView
正常运行的功能,我想通过使用列表作为模板并添加分支到更多此类列表中的Tabs(类别)来扩展它。我使用ListView
完成了它,似乎添加标签需要我通过扩展tabview
重写我的整个代码。有没有办法在实现我的标签时可以使用ListView
?
我注意到没有关于如何一起实现这两个视图/布局的教程,任何人都有任何链接和方向?
答案 0 :(得分:3)
我刚才在一些代码中有一个例子。
我需要的还是一个标签内的列表。因此,驱动程序是其中包含其他活动的选项卡。您将具有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;
}
}