2

The Tab Layout tutorial on the Android Developers site shows how to add tabs to a TabHost with a lot of repetitive procedural code.

Is there a declarative way to create tabbed layouts on Android? Something like the following?

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

(If this existed, the FrameLayout would show only one child view at a time.)

Bart
  • 21
  • 1

1 Answers1

0

Unfortunately, no. (I got this error previously: body must be at least 30 characters; you entered 18)

Randy Sugianto 'Yuku'
  • 64,635
  • 54
  • 168
  • 216