2011-04-18 38 views
2

Tab Layout tutorial on the Android Developers site顯示瞭如何使用大量重複的程序代碼將選項卡添加到TabHost。有沒有一種聲明方式在Android上創建選項卡式佈局?

是否有聲明的方式來在Android上創建選項卡式佈局?像下面這樣的東西?

<?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"> 
      <Tab android:text="Artists" 
       android:icon="@drawable/ic_tab_artists" 
       android:href="artists_frame"/> 
      <Tab android:text="Albums" 
       android:icon="@drawable/ic_tab_albums" 
       android:href="albums_frame"/> 
      <Tab android:text="Songs" 
       android:icon="@drawable/ic_tab_songs" 
       android:href="songs_frame"/> 
     </TabWidget> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp"> 
      <TextView android:id="artists_frame" 
         android:text="This is the Artists tab."/> 
      <TextView android:id="albums_frame" 
         android:text="This is the Albums tab."/> 
      <TextView android:id="songs_frame" 
         android:text="This is the Songs tab."/> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

(如果存在,則FrameLayout裏將只顯示一次一個子視圖。)

回答

0

不幸的是,沒有。 (我以前得到這個錯誤:正文必須至少有30個字符;你輸入了18)

相關問題