2012-05-07 8 views
0

私は単純なフラグが必要だと確信していますが、正しい解決策を見つけるのに少なくとも2時間かかっています。あなたからの助けを得ることを願っています。 fragmentActivityを使用して2つのタブレイアウトを作成しようとしています。私は各タブに50%のスクリーンスペースを与えたいと思っています。私は次のハードルが、私はタブのヘッダーが欲しいです(添付のスクリーンショットを参照してください)を行うことができます。黒bkgでの財政は50%、残りはゲイリーbkgで残りの50%を取る必要があります。 enter image description hereフラグメントタブのヘッダー/ラベルのサイズ

私は私の質問で明確です。 :-)

attaching my xml 
<?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" 
    android:background="#EFEFEF" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" /> 

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

      <FrameLayout 
       android:id="@+id/financial" 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_weight="0" 
       android:tag="@string/financial" /> 

      <FrameLayout 
       android:id="@+id/other" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:tag="@string/others" /> 
     </FrameLayout> 
    </RelativeLayout> 

</TabHost> 


**The calling xml would be** 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="fill_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/textView1" > 
    </ListView> 

    <fragment 
    class="com.......android.activity.AccountsTab" 
     android:id="@+id/tabs_fragment" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerInParent="true"/> 
</RelativeLayout> 

tab.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="150dp" 
    android:layout_height="@dimen/tab_height" 
    android:background="@drawable/tab_selector" 
    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:padding="@dimen/tab_padding" 
    android:weightSum="0.5" > 

    <TextView 
     android:id="@+id/text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:gravity="center_horizontal|center_vertical" 
     android:textColor="@drawable/tab_text_selector" 
     android:textSize="@dimen/text_default" 
     android:textStyle="italic" /> 

</RelativeLayout> 
+0

両方のタブのサイズが同じである必要がありますか? – Rookie

+0

@ Raghavはい、どちらも有効な画面幅を占有する必要があります。また、各タブの左側にアイコンを設定したいと思います。注:アイコンの動作は異なります。私は問題のtab.xmlを追加しました。 – mask

答えて

0

を追加し、私はあなたがこのようにそれをやるべきだと思います。

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

      <TabWidget 
       android:id="@android:id/tabs" 
       android:orientation="horizontal" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="0" 
       /> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="0dp" 
       android:layout_height="0dp" 
       android:layout_weight="0"/> 

      <FrameLayout 
       android:id="@+android:id/realtabcontent" 
       android:layout_width="fill_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1"/> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

これで、必要な数のタブを追加できます。

enter image description here 希望します。

+0

あなたの答えをありがとう、私はそれを別の方法でしたが、私はそれを試み、私のために働いた。私は答えとしてマークします。 – mask

関連する問題