Android 列表视图项显示在选项卡视图的选项卡下

Android 列表视图项显示在选项卡视图的选项卡下,android,android-widget,Android,Android Widget,显示时,列表视图的前两行显示在选项卡下,水星和金星行星。如何使选项卡占据顶部,并使listview行在选项卡之后开始 tablistmenu.xml: tablistmenu.java: 公共类tablistmenu扩展TabActivity{ 私有ListView主ListView; 专用阵列适配器列表适配器; 创建时的公共void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); requestWindowFe

显示时,列表视图的前两行显示在选项卡下,水星和金星行星。如何使选项卡占据顶部,并使listview行在选项卡之后开始

tablistmenu.xml:


tablistmenu.java:

公共类tablistmenu扩展TabActivity{
私有ListView主ListView;
专用阵列适配器列表适配器;
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.tablistmenu);
TabHost mTabHost=getTabHost();
mTabHost.addTab(mTabHost.newTabSpec(“tab_test1”).setIndicator(“Contacts”,getResources().getDrawable(R.drawable.contact_32)).setContent(R.id.textview1));
mTabHost.addTab(mTabHost.newTabSpec(“tab_test2”).setIndicator(“信用卡”,getResources().getDrawable(R.drawable.Credit_card_32)).setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec(“tab_test3”).setIndicator(“Notes/Misc”,getResources().getDrawable(R.drawable.Notes_32)).setContent(R.id.textview3));
mTabHost.addTab(mTabHost.newTabSpec(“tab_test4”).setIndicator(“网站”,getResources().getDrawable(R.drawable.globe_32)).setContent(R.id.textview4));
mTabHost.setCurrentTab(0);
//查找ListView资源。
mainListView=(ListView)findViewById(R.id.lstMain);
//创建并填充行星名称列表。
字符串[]行星=新字符串[]{“水星”、“金星”、“地球”、“火星”,
“木星”、“土星”、“天王星”、“海王星”};
ArrayList planetList=新的ArrayList();
planetList.addAll(Arrays.asList(planets));
//使用行星列表创建ArrayAdapter。
listAdapter=new ArrayAdapter(这个,R.layout.simplerow,planetList);
//将ArrayAdapter设置为ListView的适配器。
mainListView.setAdapter(listAdapter);
//结束
}
}  
}
谢谢, Dean

有关详细信息,请参见本教程,但基本上它希望在TabHost下使用TabWidget和FrameLayout进行线性布局。您的内容将放在框架布局下:

<?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"?>
<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">
        <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">
            <TextView 
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview4"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
                    <ListView 
android:id="@+id/lstMain" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</ListView>
        </FrameLayout>
     </LinearLayout>

       </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"?>
<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">
        <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">
            <TextView 
                android:id="@+id/textview1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
            <TextView 
                android:id="@+id/textview4"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="" />
                    <ListView 
android:id="@+id/lstMain" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</ListView>
        </FrameLayout>
     </LinearLayout>

       </TabHost>