在Android上是否有一种声明式的方式来创建选项卡布局?



Android开发人员网站上的标签布局教程展示了如何使用大量重复的过程代码向TabHost添加标签。

是否有一个声明式的方式来创建标签布局在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>

(如果存在,framayout将一次只显示一个子视图)

遗憾的是,没有。(我以前得到过这个错误:正文必须至少30个字符;

最新更新