2012-02-10 11 views
0

私はAndroidの開発者とXMLに全く新しいです。私がしようとしているのは、画面の下部に4つのタブを作成し、タブが画面の幅を埋めることです。私は、下部に4つのタブを作成することができましたが、幅はすべて "fill_parent"に設定されていますが、タブウィジェットは幅を埋めるものではありません。しかし、Eclipseのグラフィカルレイアウトでは、幅を埋めるウィジェットが表示されます。誰も助けることができますか?コードは以下のとおりです。ありがとう。Androidタブウィジェットは画面の幅を埋めません

<?xml version="1.0" encoding="utf-8"?> 
<!-- Dublin Bus App --> 

<TabHost 
    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/tab_host"> 

    <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom"/> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <LinearLayout 
      android:id="@+id/tab1" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:padding="5px" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the first tab" 
       android:textSize="25dp" 
       android:layout_gravity="center" 
       android:textStyle="bold"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab2" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the second tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
      </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab3" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the third tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/tab4" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5px"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="This is the fourth tab" 
       android:layout_gravity="center" 
       android:textStyle="bold" 
       android:textSize="25dp"/> 
     </LinearLayout>    
    </FrameLayout> 
</TabHost> 
+0

あなたは同じことをするための解決策を得ましたか?あなたが使用しているAndroidのバージョンを知ることができますか?おかげで – vinaykumar

答えて

4

あなたの問題はTabHostが一つだけの要素を保持するための説明状態として、ある、FrameLayout、由来することで、あなたがそれを詰めています2つ:TabWidgetとFrameLayout。

はこれを試してみてください(私もでframeLayoutを削除する方法に注意してください - それは悪い考えであるように、タブに記入しようとしている)

<?xml version="1.0" encoding="utf-8"?> 
<!-- Dublin Bus App --> 

<TabHost 
    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/tab_host"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom"/> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" /> 
    </LinearLayout> 
</TabHost> 

そして、コンテンツにタブを埋めるためにthe HelloTabWidget tutorialに従ってください。

0

てみアンドロイド:幅=「match_parent」

+0

こんにちは、アンドロイド:layout_width = "match_parent"同じ問題が発生します – sineil

関連する問題