8

Ich habe unter xml Datei, die 1) Toolbar 2) TabLayout 3) Custom View und 4) ViewPager hat. Wenn ich Toolbar setzen, TabLayout, Custom View innen AppBarLayout, drückt er ViewPager sich wie wie folgt aus:Android AppBarLayout schiebt ViewPager runter

enter image description here

xml:

<?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:id="@+id/feed_coordinator_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 


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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_tool_bar_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleTextAppearance="@style/Widget.AppCompat.ActionBar.TabText" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:statusBarScrim="?attr/colorAccent"> 


      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar_alt" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="@color/primary_color" 
       android:minHeight="?attr/actionBarSize" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:layout_collapseMode="none" 
       app:layout_scrollFlags="scroll|exitUntilCollapsed" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 


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

     <android.support.design.widget.TabLayout 
      android:id="@+id/feed_sliding_tabs_alt" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabGravity="fill" 
      app:tabMode="fixed" 
      app:tabSelectedTextColor="@color/accent_color" 
      app:tabTextColor="@color/accent_color_per_70" /> 

     <LinearLayout 
      android:id="@+id/activity_feed_fl_canli_skor" 
      android:layout_width="match_parent" 
      android:layout_height="52dp" 
      android:background="@drawable/mac_back" 
      android:orientation="vertical"> 


     </LinearLayout> 

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

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


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floating_action_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_feed_new_post" 
     android:theme="@style/FabTheme" 
     android:visibility="invisible" 
     app:backgroundTint="@color/primary_color" 
     app:borderWidth="0dp" 
     app:layout_anchor="@id/feed_coordinator_layout" 
     app:layout_anchorGravity="bottom|right|end" /> 
</android.support.design.widget.CoordinatorLayout> 

Wenn ich nach unten scrollen, Toolbar wird versteckt, was gut ist. Aber My ViewPager überläuft Hauptbildschirm und Unterseite ViewPager ist nicht sichtbar. Was kann ich versuchen?

Wenn ich nach oben scrollen Toolbar wird unsichtbar und ViewPager ist hochgezogen und voll sichtbar im Bildschirm. Aber Toolbar reagiert nur auf Scroll der ersten Seite von ViewPager. Trick: Vorerst setzen i paddingBottom innen ViewPager frament

+0

Lief in das gleiche Problem und musste das CoordinatorLayout entfernen und durch ein LinearLayout ersetzen, damit der ViewPager den Bildschirm nicht überläuft. Für mich ist das einfacher. Vielleicht nicht die beste Lösung für andere. –

+0

Hallo, ich habe das gleiche Problem. Hast du es geschafft, es zu reparieren? –

+1

@GeorgiKoemdzhiev Nein, fügen Sie einfach Padding an der Unterseite des Fragments in ViewPager, so dass der untere Teil des Fragments sichtbar sein wird –

Antwort

2

Dies ist keine wirkliche Lösung, aber für vorerst Ich habe diese Codezeile im Hinblick auf Pager und seine Arbeits:

android:paddingBottom="?attr/actionBarSize" 

so meine volle Layout ist:

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

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme.PopupOverlay"> 

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

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

<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="?attr/actionBarSize" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v4.view.PagerTabStrip 
     android:id="@+id/pager_header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="top" 
     android:paddingBottom="4dp" 
     android:paddingTop="4dp" /> 

</android.support.v4.view.ViewPager> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="end|bottom" 
    android:layout_margin="@dimen/fab_margin" 
    android:src="@mipmap/ic_search" />