2017-09-30 8 views
0

MainActivityのタブレイアウトはViewPagerですが、MainActivityにボトムナビゲーションを追加していますが、ViewPagerが下部ナビゲーションの上部に表示されるようにします。ここでデバイスの画面の高さに関係なくViewPagerの高さを設定する方法は?

が私の主な活動のレイアウトが

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical"> 


<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <TextView 
     android:id="@+id/logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10sp" 
     android:paddingTop="10sp" 
     android:textAlignment="center" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:textColor="@color/white" 
     android:textStyle="bold" 
     android:textSize="40sp" 
     android:text="@string/app_name" /> 



    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:layout_gravity="top" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <include layout="@layout/bottom_nav"></include> 

</android.support.design.widget.CoordinatorLayout> 

ある現在ViewPagerは、下部のナビゲーションバーの背後にある完全な高さにまたがります。私は私のViewpager親のレイアウトなどenter image description here

答えて

1

以下の利用 LinearLayoutのようになりたいとも、あなたの ViewPagerに重みを設定します。それはあなたのケースで動作します。以下のコードを確認してください。

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical"> 


<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <TextView 
     android:id="@+id/logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10sp" 
     android:paddingTop="10sp" 
     android:textAlignment="center" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:textColor="@color/white" 
     android:textStyle="bold" 
     android:textSize="40sp" 
     android:text="@string/app_name" /> 



    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:layout_gravity="top" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

    <include layout="@layout/bottom_nav"></include> 

</LinearLayout> 
+0

これは問題を解決しますが、なぜ私が最初にCoordinatorLayoutを使用していたのか分かりませんが、感謝します。 –

+0

@vikasdevdeもしあなたがそれを助けてくれたら、私の投稿を受け入れて他の人にとって役に立ちますようにしてください。 – Kuls

0

座標レイアウト後に親レイアウトとしてライナーレイアウトを使用します。

<android.support.design.widget.CoordinatorLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <TextView 
     android:id="@+id/logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingBottom="10sp" 
     android:paddingTop="10sp" 
     android:textAlignment="center" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:textColor="@color/white" 
     android:textStyle="bold" 
     android:textSize="40sp" 
     android:text="@string/app_name" /> 
    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabMode="fixed" 
     app:tabGravity="fill"/> 
</android.support.design.widget.AppBarLayout> 
<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:layout_gravity="top" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
<include layout="@layout/bottom_nav"></include> 
</LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 
関連する問題