3

私のプロジェクトにはTabHostアクティビティがあります。次のXMLがあると、タブは画面外にあり、まったく表示されません。私は少しこのように見えるように変更した場合アンドロイド:layout_marginBottomはスペースを最下部に残さない

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activityVerticalMargin" 
    android:paddingLeft="@dimen/activityHorizontalMargin" 
    android:paddingRight="@dimen/activityHorizontalMargin" 
    android:paddingTop="@dimen/activityVerticalMargin" 
    tools:context=".SomeActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="50dp"> 

      <some elements here> 

     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" /> 

    </LinearLayout> 

</TabHost> 

ただし、タブが表示されますが、彼らは一番下にありません、それは私がそれを見てみたいかではありません。

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tabHost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activityVerticalMargin" 
    android:paddingLeft="@dimen/activityHorizontalMargin" 
    android:paddingRight="@dimen/activityHorizontalMargin" 
    android:paddingTop="@dimen/activityVerticalMargin" 
    tools:context=".SomeActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="50dp"> 

      <!-- layout_height above was changed to wrap_content --> 

      <some elements here> 

     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" /> 

    </LinearLayout> 

</TabHost> 

なぜ最初のケースで機能しないのですか? layout_marginBottomはレイアウトの高さをmatch_parent - margin(この場合は50dp)にしないといけませんか?

+0

あなたのコードはmatch_parent - 100dp(50dpのタブウェイトと50dpのmarginBottom)を行います。 Match_parentは、線形レイアウトに残っているすべてのスペースを占有します。相対的な場合、match_parent - 50dp(マージンボトムの50dp) – suku

+0

これをどのように変更する必要がありますか? – pratnala

+0

親LinearLayoutをRelativelayoutに変換します。フレームレイアウトのパラメータはalign_parenttop = trueで、tabwidgetのalign_parentBottom = trueである必要があります。残りは残しておきなさい。 – suku

答えて

1

親LinearLayoutをRelativelayoutに変換します。フレームレイアウトのパラメータはalign_parenttop = trueで、tabwidgetのalign_parentBottom = trueである必要があります。残りは残しておきなさい。

1

これを行う方法は、LinearLayoutです(とにかくRelativeLayoutは避ける必要があります)。あなたのTabWidget要素にマイナスのマージンを与えることができます。レイアウトは次のようになります。

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/tabHost" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activityVerticalMargin" 
     android:paddingLeft="@dimen/activityHorizontalMargin" 
     android:paddingRight="@dimen/activityHorizontalMargin" 
     android:paddingTop="@dimen/activityVerticalMargin" 
     tools:context=".SomeActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="50dp"> 

      <!-- some elements here --> 

     </FrameLayout> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_marginTop="-50dp"/> 

    </LinearLayout> 

</TabHost> 
関連する問題