2017-09-30 4 views
0

ich eine Registerkarte Layout in MainActivity haben, die ViewPager hat, bin ich auch unten Navigation zu MainActivity Hinzufügen möchte ich ViewPager der Höhe sein, dass sie die Oberseite der unteren Navigations berührt.Wie wird die Höhe von ViewPager unabhängig von der Bildschirmhöhe des Geräts eingestellt?

Hier ist meine Haupttätigkeit Layout

<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> 

Derzeit ViewPager erstreckt sich über volle Höhe hinter unteren Navigationsleiste. Ich möchte, dass meine Viewpager wie LinearLayout als Eltern Layout unter

enter image description here

Antwort

1

Verwendung sein und auch zu Ihrem ViewPager eingestellt Gewicht. Es würde in Ihrem Fall funktionieren. Überprüfen Sie den folgenden Code.

<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

Dies löst das Problem, aber ich bin mir nicht sicher, warum ich CoordinatorLayout in erster Linie verwendet habe, aber danke. –

+0

@vikasdevde Wenn es Ihnen dann hilft, dann akzeptieren Sie bitte meine Post eine Antwort, so dass es für andere nützlich wäre. – Kuls

0

Verwenden Sie das Liner-Layout als übergeordnetes Layout nach dem Koordinatenlayout.

<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> 
Verwandte Themen