2

Ich habe eine NestedScrollView in einem CoordinatorLayout und es enthält eine RecyclerView. Das ganze Fragment, das sehr lang ist, hat kein Scroll-Momentum und ich bin nicht sicher, was ich tun kann, um es zu reparieren. Ich hatte vorher dieses Problem mit höheren Android-Versionen und war in der Lage,API 19 Scrollview kein Impuls

zu schließen, um mein Problem zu lösen. Dies wurde jedoch in API 21 hinzugefügt und mein Projekt unterstützt 19+. Meine App hat immer noch keine Auswirkungen auf dieses Fragment für api 19 Geräte.

Unten ist mein xml:

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="@color/primary_color" 
    android:fitsSystemWindows="true"> 

<android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"> 

    <android.support.percent.PercentRelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:nestedScrollingEnabled="false"> 

     <ImageView 
       android:id="@+id/logo" 
       android:src="@drawable/logo" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/profile_margin_medium_huge" 
       android:layout_marginBottom="46dp" 
       android:layout_marginRight="@dimen/activity_horizontal_margin" 
       android:layout_marginLeft="@dimen/activity_horizontal_margin" 
       android:layout_alignParentEnd="true"/> 

     <TypefaceTextView 
       android:id="@+id/textview_title" 
       android:layout_below="@id/logo" 
       android:text="@string/title" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       style="@style/myStyle" 
       android:layout_marginLeft="@dimen/activity_horizontal_margin" 
       android:layout_marginRight="@dimen/activity_horizontal_margin" 
       android:layout_marginBottom="16dp" 
       android:layout_alignParentLeft="true"/> 

     <TypefaceTextView 
       android:id="@+id/textview_byline" 
       android:text="@string/byline" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       style="@style/myStyle" 
       android:layout_below="@id/textview_title" 
       android:layout_marginLeft="@dimen/activity_horizontal_margin" 
       android:layout_marginRight="@dimen/activity_horizontal_margin" 
       android:layout_marginBottom="40dp"/> 

     <RadioGroup 
       android:id="@+id/radiogroup_filter" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_below="@id/textview_byline" 
       android:layout_alignParentRight="true" 
       android:layout_marginLeft="@dimen/activity_horizontal_margin" 
       android:layout_marginRight="@dimen/activity_horizontal_margin" 
       android:layout_marginBottom="@dimen/activity_vertical_margin"> 

      <TypefaceRadioButton 
        android:id="@+id/button_filter_new" 
        android:text="@string/filter_new" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        style="@style/buttonStyleRadio" 
        android:theme="@style/ButtonSecondary" 
        android:button="@null"/> 

      <TypefaceRadioButton 
        android:id="@+id/button_filter_history" 
        android:text="@string/filter_history" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        style="@style/ButtonStyleRadio" 
        android:theme="@style/ButtonSecondary" 
        android:layout_alignParentRight="true" 
        android:button="@null"/> 

     </RadioGroup> 
     <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerview" 
       android:nestedScrollingEnabled="false" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/radiogroup_filter" 
       android:layout_marginLeft="@dimen/activity_horizontal_margin" 
       android:layout_marginRight="@dimen/activity_horizontal_margin" 
       android:layout_marginBottom="50dp"/> 
     <android.support.percent.PercentRelativeLayout 
       android:id="@+id/container_links" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/recyclerview" 
       android:visibility="gone"> 
      <ImageView 
        android:id="@+id/image_link_1" 
        app:layout_widthPercent="100%" 
        app:layout_aspectRatio="158%" 
        android:scaleType="centerCrop" 
        android:layout_alignParentTop="true"/> 
      <TypefaceTextView 
        android:id="@+id/text_link_1" 
        android:text="@string/text_1" 
        app:layout_widthPercent="100%" 
        app:layout_aspectRatio="158%" 
        android:gravity="bottom|left" 
        android:paddingLeft="@dimen/activity_horizontal_margin" 
        android:paddingRight="@dimen/activity_horizontal_margin" 
        android:paddingTop="32dp" 
        android:paddingBottom="32dp" 
        style="@style/myStyle" 
        android:layout_alignParentTop="true"/> 
      <ImageView 
        android:id="@+id/image_link_2" 
        app:layout_widthPercent="100%" 
        app:layout_aspectRatio="158%" 
        android:scaleType="centerCrop" 
        android:layout_below="@id/image_link_1"/> 
      <TypefaceTextView 
        android:id="@+id/text_link_2" 
        android:text="@string/text_2" 
        app:layout_widthPercent="100%" 
        app:layout_aspectRatio="158%" 
        android:gravity="bottom|right" 
        android:paddingLeft="@dimen/activity_horizontal_margin" 
        android:paddingRight="@dimen/activity_horizontal_margin" 
        android:paddingTop="32dp" 
        android:paddingBottom="32dp" 
        android:layout_below="@id/image_link_1" 
        style="@style/myStyle"/> 
     </android.support.percent.PercentRelativeLayout> 
    </android.support.percent.PercentRelativeLayout> 
</android.support.v4.widget.NestedScrollView> 

+0

zwingende Sie die OnTouch oder onDispatchTouch in Ihrer Anwendung? –

+0

@LeandroBorgesFerreira Ich bin nicht:/ – kjanderson2

+0

Versuchen Sie, die Support-Bibliothek in Ihrer Note-Datei und Ihre Build-Tools zu aktualisieren –

Antwort

4

Ich war in der Lage, Ihre Symptome in meinem Test-Projekt neu zu erstellen. Ich reparierte es den folgenden Code in onCreate das Hinzufügen() für die Aktivität:

final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); 
recyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() { 
     @Override 
     public boolean onFling(int velocityX, int velocityY) { 
      recyclerView.dispatchNestedFling(velocityX, velocityY, false); 
      return false; 
     } 
    }); 

ich einen Seitensprung Zuhörer zum RecyclerView hinzugefügt und in onFling() Ich nenne dispatchNestedFling(), um die Eltern zu informieren, dass ein Schleuder tritt auf. Der Elternteil kann dann den Fling konsumieren oder das Kind beobachten.

https://developer.android.com/reference/android/support/v4/view/NestedScrollingChild.html#dispatchNestedFling(float, float, boolean)

dispatchNestedFling

22.1.0 boolean dispatchNestedFling in Version hinzugefügt (float velocityX, float velocityY, boolean verbraucht) Versendung einen Seitensprung zu einer verschachtelten Scrollen Elternteil.

Diese Methode sollte verwendet werden, um anzuzeigen, dass ein verschachteltes untergeordnetes untergeordnetes Objekt geeignete Bedingungen für einen Fling erkannt hat. Im Allgemeinen bedeutet dies , dass ein Touch Scroll mit einer Geschwindigkeit in Richtung Scrollen beendet wurde, die die minimale Schleudergeschwindigkeit entlang einer rollbaren Achse erfüllt oder überschreitet.

Wenn eine verschachtelte Scrollen Kind Ansicht normalerweise schleudern würde, aber es ist an der Rand seines eigenen Inhalte, kann es diese Methode verwenden, um die fling seiner verschachtelten Scrollen Eltern statt zu delegieren. Der Elternteil kann wahlweise den Fling konsumieren oder einen Kinderschleudern beobachten.

Dies funktioniert auf meinem Emulator mit API 19. Offensichtlich YMMV.

+0

Yay! Es hat für mich funktioniert! – kjanderson2

+0

Gut! Ich bin froh, dass ich helfen konnte! –

+0

Arbeitete für mich ... Danke Mann !. –

1

Es gibt einen einfacheren Weg:

Java

recyclerView.setNestedScrollingEnabled(false); 

Kotlin

recyclerView.isNestedScrollingEnabled = false 
+0

Haben Sie die Frage gelesen? Ich habe es versucht, aber es funktioniert nicht für api 19 ... Die angenommene Antwort hat funktioniert. – kjanderson2

+0

@ kjanderson2 Dude, es funktioniert nicht auf XML, aber es funktioniert, wenn Sie es in OnCreate setzen. –

+0

Yeh Mann du bist absolut richtig! Es funktioniert (y) –

Verwandte Themen