2012-06-22 4 views

답변

0

할 수 있습니다. 아래의 기초.

tablayout.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:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:padding="5dp" > 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="30dp" 
      android:gravity="bottom" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" > 
      <!-- General Info Tab --> 
      <LinearLayout 
       android:id="@+id/general_tab" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 
      </LinearLayout> 
      <!-- Tool Tab --> 
      <LinearLayout 
       android:id="@+id/list_tab" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" > 
       <ExpandableListView 
        android:id="@+id/list1" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="1" 
        android:drawSelectorOnTop="false" /> 
      </LinearLayout> 
     </FrameLayout> 
    </LinearLayout 
</TabHost> 

TabDemo.java

public class TabDemo extends TabActivity { 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tablayout); 

     tabHost = getTabHost(); 
     TabHost.TabSpec spec; 
     spec = tabHost.newTabSpec("General").setIndicator("General") 
       .setContent(R.id.general_tab); 
     tabHost.addTab(spec); 
     spec = tabHost.newTabSpec("List").setIndicator("List") 
       .setContent(R.id.list_tab); 
     tabHost.addTab(spec); 
     populateTabs(); // your method to populate the tabs 
    } 
관련 문제