我正在尝试使用 tabhost 将 ListView 放在第一个选项卡中的另一个 ListView 下方。
我想要这样的原因是因为我想按类型划分交易卡列表,所以我想创建部分或其他什么。
这是我的.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/banlistdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="Banlist Date: March, 2013"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/banlistdate" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:id="@+id/fLV1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF8B53"
tools:listheader="@layout/banlist_header_effectmonsters" >
</ListView>
<ListView
android:id="@+id/fLV2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#a086b7"
tools:listheader="@layout/banlist_header_fusionmonsters" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/flv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
这是我启动选项卡和设置 ListViews 的主要 java 文件:
package cybertech.productions.yugiohlibrary;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Banlist extends Activity implements OnClickListener {
TabHost th;
Initializers initialMngr;
ArrayAdapter<String> listAdapter;
ListView forbiddenEMListView, forbiddenFListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.banlist);
th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Forbidden");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("Semi-Limited");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Limited");
th.addTab(specs);
th.setCurrentTab(0);
// #BEGIN: Tab 1 ListViews
//Setup the "forbidden" ListView(s);
// ListView 1: Effect Monsters
forbiddenEMListView = (ListView) findViewById(R.id.fLV1);
ArrayList<String> forbiddenEMList = new ArrayList<String>();
forbiddenEMList.addAll(Arrays.asList(initialMngr.forbiddenEM));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenEMList);
View effectMon_header = View.inflate(this, R.layout.banlist_header_effectmonsters, null);
forbiddenEMListView.addHeaderView(effectMon_header);
forbiddenEMListView.setAdapter(listAdapter);
// ListView 2: Fusion Monsters
forbiddenFListView = (ListView) findViewById(R.id.fLV2);
ArrayList<String> forbiddenFList = new ArrayList<String>();
forbiddenFList.addAll(Arrays.asList(initialMngr.forbiddenF));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenFList);
View fusion_header = View.inflate(this, R.layout.banlist_header_fusionmonsters, null);
forbiddenFListView.addHeaderView(fusion_header);
forbiddenFListView.setAdapter(listAdapter);
// #END: Tab 1 ListViews
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
谢谢你的帮助。