2010-08-16 84 views
0

當這顯示列表視圖的前兩行出現在選項卡,水星和金星行星下。如何讓選項卡佔據頂部和列表視圖行以在選項卡之後啓動?列表視圖項目出現在tabview標籤下

tablistmenu.xml:

<?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="" /> 
     </FrameLayout> 

    </LinearLayout> 

     <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 


<ListView 
android:id="@+id/lstMain" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
</ListView> 
    </LinearLayout> 
    </TabHost> 

tablistmenu.java:

public class tablistmenu extends TabActivity { 




    private ListView mainListView ; 
     private ArrayAdapter<String> listAdapter ; 


     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 

     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("Credit Cards", 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("Websites", getResources().getDrawable(R.drawable.globe_32)).setContent(R.id.textview4)); 

      mTabHost.setCurrentTab(0); 



      // Find the ListView resource. 
      mainListView = (ListView) findViewById(R.id.lstMain); 

      // Create and populate a List of planet names. 
      String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars", 
               "Jupiter", "Saturn", "Uranus", "Neptune"};  
      ArrayList<String> planetList = new ArrayList<String>(); 
      planetList.addAll(Arrays.asList(planets)); 

      // Create ArrayAdapter using the planet list. 
      listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, planetList); 

      // Set the ArrayAdapter as the ListView's adapter. 
      mainListView.setAdapter(listAdapter); 


      // End 


     } 


     } 
     } 

感謝, 院長

回答

1

Hello Tab Layout教程瞭解詳細信息,但基本上它預計在TabHost下帶有TabWidget和FrameLayout的LinearLayout。您的內容將在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> 
-1

我將我的代碼更改爲以下,它的工作完美。謝謝Mayra!

<?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>