2016-04-10 8 views
2

Ich bin neu in Android-Entwicklung und ich bin mit dem folgenden Problem konfrontiert. Dies ist das Layout meiner Haupttätigkeit:ViewPager erstreckt sich über den unteren Rand des Bildschirms

<?xml version="1.0" encoding="utf-8"?> 

<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.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar_main" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:layout_scrollFlags="scroll|enterAlways"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/white" 
       app:tabTextColor="@color/selected_text" 
       app:tabSelectedTextColor="@color/white"/> 

     </android.support.v7.widget.Toolbar> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

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

Für jede Registerkarte im ViewPager ich ein Fragment haben, und das ist das Layout einer von ihnen

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@color/colorPrimary" 
    android:id="@+id/linear_layout" 
    tools:context=".fragments.Reviews"> 

    <RatingBar 
     android:id="@+id/review_totalRating" 
     style="?android:attr/ratingBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:numStars="5" 
     android:stepSize=".5" 
     android:isIndicator="true" 
     android:progressTint="@color/golden" 
     android:layout_gravity="center" 
     android:paddingTop="10dp" 
     android:paddingBottom="5dp" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="8dp" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:id="@+id/listView_reviews" /> 

</LinearLayout> 

Dann habe ich meine Listview füllen mit Elemente, deren Layout in einer anderen XML-Datei definiert ist. Mein Problem ist mit dem ViewPager layout_height: es ist jetzt auf match_parent gesetzt, aber das Element erstreckt sich über den unteren Bildschirmrand mit dem Ergebnis, dass das letzte Element der ListView von den Navigationsschaltflächen abgedeckt wird. Dies ist, was ich im Design-Editor sehen ViewPager overflow

Wie kann ich das Element vor den Navigationstasten stoppen?

Antwort

5

Ich konfrontiert dieses Problem auch. Es ist wegen AppBarLayout Verhalten in CoordinatorLayout. Wenn Sie ein Projekt aus einer Vorlage erstellen, wird standardmäßig das Layout mit dem Verbergen von Toolbar eingerichtet. Sie können Ihr Beispiel ausführen und es überprüfen - wischen Sie einfach die Symbolleiste nach oben und es wird ausgeblendet und ViewPager wird nach oben und dann richtig am unteren Rand des Bildschirms bleiben.

In einigen Fällen ist dies keine Lösung, daher können Sie dieses Verhalten deaktivieren, indem Sie das Attribut app:layout_scrollFlags aus Ihrer Toolbar entfernen. Danach wird die Symbolleiste unsichtbar und die ViewPager berechnet die eigene Höhe korrekt.

+0

ich konfrontiert zu dem gleichen Problem und Ihr Vorschlag war hilfreich. Wird eine Listview anstelle einer Recyclerview verwendet? – dna

1

Ich löste mit einem LinearLayout als einziges Kind des CoordinatorLayout, so dass alles andere zu einem Kind des LinearLayout wird. Es scheint mir nur ein einfacher Workaround zu sein, keine endgültige Lösung, aber jetzt funktioniert es. Dies ist nun das Layout meiner Haupttätigkeit:

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

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

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar_main" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:elevation="4dp" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:tabIndicatorColor="@color/orange_050" 
       app:tabSelectedTextColor="@color/orange_050" 
       app:tabTextColor="@color/orange_050"/> 

     </android.support.v7.widget.Toolbar> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/main_pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

</LinearLayout> 

Verwandte Themen