2011-04-18 69 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)

相关问题