3

내 프로젝트에 TabHost 활동이 있습니다. 다음 XML을 사용하면 탭이 화면에서 벗어나 전혀 표시되지 않습니다. 나는 약간이처럼 보이도록 수정하면android : 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의 tabweight 및 50dp의 marginBottom)를 수행합니다. Match_parent는 선형 레이아웃에 남아있는 모든 공간을 차지합니다. relativelayout에서 match_parent - 50dp (marginbottom의 50dp) – suku

+0

그래서 어떻게 변경해야합니까? – pratnala

+0

부모 LinearLayout을 Relativelayout로 변환합니다. 프레임 레이아웃에는 매개 변수 align_parenttop = true가 있어야하고 tabwidget에는 align_parentBottom = true가 있어야합니다. 나머지는 남겨 둡시다. – suku

답변

1

Convert parent LinearLayout to 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> 
관련 문제