2011-08-09 7 views
4

レイアウトxmlファイル内でのみタブレイアウトを定義できますか? Tabhostチュートリアルを見つけるたびに、いくつかの追加のJavaコードでしか動作しません。​​がTabHostの各タブを表しホルダークラスであるとして、コードなしでxmlファイル内にTabhost/TabWidget +コンテンツを定義することは可能ですか?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/linearLayout"> 
    <TextView android:text="@string/app_name" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge"></TextView> 
    <TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"> 
     <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"> 
     </TabWidget> 
     <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent"> 
      <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1"> 
       <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 1"/> 
      </LinearLayout> 
      <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"> 
       <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TAB 2"/> 
      </LinearLayout> 
     </FrameLayout> 
    </TabHost> 
</LinearLayout> 

答えて

1

そのことはできません:

は、ここで任意のタブが表示されません私のtest.xmlです。 であり、xmlレイアウトに配置するために指定されたTabSpec xml相当のタグはありません。

コードでさえ、TabSpecの場合、インジケータとコンテンツの両方を指定する必要があります。それ以外の場合は、どちらか

IllegalArgumentException: you must specify a way to create the tab content 

または

IllegalArgumentException: you must specify a way to create the tab indicator. 
がスローされます
関連する問題