5

Ich habe eine einfache App mit einem Viewpager mit 3 Fragmenten. In einem der Fragmente habe ich Recyclerview Liste. Wenn Sie nach unten scrollen, wird die Symbolleiste minimiert und beim Scrollen angezeigt. Mein Problem ist, wenn die Werkzeugleiste kollabiert ist und ich scrolle nach links/rechts. Ich erweitere es programmatisch und schiebe den viewpager nach unten, anstatt ihn nur zu überlappen. Dies führt zu einer nicht angenehmen Verschiebung der Ansichten des Bildschirms. Wie kann ich die Symbolleiste mit meinem Viewpager überlappen, anstatt sie beim Expandieren nach unten zu drücken? Ich machte eine kurze Aufzeichnung des Problems clickViewpager wird aus dem Bildschirm geschoben [CoordinatorLayout] [Design Library]

enter image description here

Das ist mein main_layout:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=".UI.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/appBarLayouy" 
     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:popupTheme="@style/AppTheme.PopupOverlay" 
      app:layout_scrollFlags="scroll|enterAlways" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/sliding_tabs" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/tabsHeight" 
      style="@style/NavigationTab"/> 


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

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


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

    <com.getbase.floatingactionbutton.FloatingActionsMenu 
     android:id="@+id/floatingActionMenu" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     fab:fab_addButtonColorNormal="@color/blood_orange" 
     fab:fab_addButtonColorPressed="@color/dirtyWhite" 
     fab:fab_addButtonPlusIconColor="@color/dirtyWhite" 
     fab:fab_addButtonSize = "normal" 
     fab:fab_labelStyle="@style/menu_labels_style" 
     fab:fab_labelsPosition="left" 
     app:layout_anchor="@id/viewpager" 
     app:layout_anchorGravity="bottom|end"> 

     <com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/createPlanBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_colorNormal="@color/blood_orange" 
      fab:fab_title="Create a plan" 
      fab:fab_size="normal" 
      app:fab_icon="@drawable/ic_event_white_48dp" 
      fab:fab_colorPressed="@color/dirtyWhite"/> 

     <com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/changeStatusBtn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      fab:fab_colorNormal="@color/blood_orange" 
      fab:fab_size="normal" 
      app:fab_icon="@drawable/ic_textsms_white_48dp" 
      fab:fab_title="Change status" 
      fab:fab_colorPressed="@color/dirtyWhite"/> 

    </com.getbase.floatingactionbutton.FloatingActionsMenu> 

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

Das ist mein Fragment ist, das die recyclerview Layout enthält:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/tab_bg"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/feedCardViewList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:clipToPadding="true" 
    xmlns:android="http://schemas.android.com/apk/res/android"/> 

</RelativeLayout> 

content_main Layout :

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".UI.MainActivity" 
tools:showIn="@layout/activity_main" 
app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


</RelativeLayout> 
+1

passiert es, wenn Sie App entfernen: layout_scrollFlags = "scroll | enterAlways"? – Blackbelt

+0

@Blackbelt Nein, tut es nicht. Kommt nur vor, wenn die Symbolleiste ausgeblendet ist und ich aus diesem Fragment blättern kann (Toolbar wird auf PageChanged des Viewpagers erweitert) –

+0

@Blackbelt - AFAIK, Dieses Flag hat nichts mit dem 'ViewPager' zu tun, ich kann mich an viele doppelte Fragen erinnern keine von ihnen hat eine Antwort – Mohsen

Antwort

4

Kam heute über dieses Problem. Ich bin mir nicht sicher, ob ich irgendwie etwas vermisse und das CoordinatorLayout falsch implementiere oder ob es ein Bug ist. Aber wenn jemand dieses Problem immer noch hat, habe ich es programmatisch gelöst, indem ich den Rand des Inhalts unterhalb der Symbolleiste basierend auf der Höhe der App-Leiste angepasst habe. Hier ist sie:

Layout-XML:

<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/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      ...collapsing toolbar content... 

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

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

    <FrameLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     ...content beneath toolbar... 

    </FrameLayout> 

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

-Code (nach dem Layout Aufblasen):

AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar); 
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar); 
FrameLayout contentLayout = (FrameLayout) view.findViewById(R.id.content); 
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { 

    @Override 
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
     ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) contentLayout.getLayoutParams(); 
     layoutParams.setMargins(0, 0, 0, appBarLayout.getMeasuredHeight() + verticalOffset); 
     contentLayout.requestLayout(); 
    } 

}); 
+0

Vielen Dank für Ihre Antwort! Ich habe es nicht getestet, aber ich werde Ihre Antwort akzeptieren, da sie die detaillierteste ist und auch anderen helfen könnte. –

+0

Es funktioniert. Hat viel geholfen! –

-2

Versuchen Sie Android:MarginBottom = "5dp" in Ihrem Viewpager-Tag, hier verwenden Sie Layour Höhe als "Match_Parent", so dass es den unteren Bereich bedeckt.

+1

Dies ist die Standardkonfiguration oder das Standarddesign von SupportLibrary. Das OP muss also nichts ändern. – Mohsen

+0

Ich habe das schon versucht, das ist eine Problemumgehung des Problems, das nur mein Layout ruiniert. –

1

Ich habe das gleiche Problem, so vorübergehend legte ich einen 55dp unteren Rand android: layout_marginBottom = "55dp" und sieht gut aus, ich hoffe, dieses Problem wird schnell behoben.

2

Mögliche Duplikat this

könnten Sie versuchen, die Toolbar ‚s Ändern app:layout_scrollFlags="scroll|enterAlways" Attribut app:layout_scrollFlags="enterAlways".

+1

Dieser hat es für mich repariert. Daumen hoch ^^ – pixelsize

0

Jeder

Ich war auch gleiche Problem.

Dieses Problem kann leicht einfach gelöst werden, indem

App entfernen: layout_scrollFlags = "scroll | enterAlways"

aus dem Code Werkzeugleiste in Ihnen XMLFILE.

ich war auch gleiche Problem begegnet aber bald nach dieser viewpager Entfernen ordnete sich in den Bildschirm (habe den Bildschirm Grenze nicht überquert)

war dies der Standard-Code

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

diese Änderung

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 

     app:popupTheme="@style/AppTheme.PopupOverlay"> 

zweite Zeile von unten.

Verwandte Themen