2017-12-21 12 views
0

Ich überprüfte this stackoverflow question Ursache, es ist sehr ähnlich, aber der Google-Bug wurde in aktuellen Versionen behoben, aber ich habe immer noch das Problem.OnClick-Methode innerhalb RecyclerView funktioniert nicht nach NestedScrollView gescrollt

Ich habe eine RecyclerView in einem NestedScrollView, nach NestedScrollView gescrollt, wenn ich auf Element in RecyclerView klicken, funktioniert OnClick-Methode nicht ordnungsgemäß.

Kann mir jemand helfen? Dank

Antwort

1

Okey, ich habe die Lösung here, fanden wir brauchen:

public class FixAppBarLayoutBehavior extends AppBarLayout.Behavior { 

public FixAppBarLayoutBehavior() { 
    super(); 
} 

public FixAppBarLayoutBehavior(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

@Override 
public void onNestedScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, 
          int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int type) { 
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, 
      dxUnconsumed, dyUnconsumed, type); 
    stopNestedScrollIfNeeded(dyUnconsumed, child, target, type); 
} 

@Override 
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, 
           View target, int dx, int dy, int[] consumed, int type) { 
    super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type); 
    stopNestedScrollIfNeeded(dy, child, target, type); 
} 

private void stopNestedScrollIfNeeded(int dy, AppBarLayout child, View target, int type) { 
    if (type == ViewCompat.TYPE_NON_TOUCH) { 
     final int currOffset = getTopAndBottomOffset(); 
     if ((dy < 0 && currOffset == 0) 
       || (dy > 0 && currOffset == -child.getTotalScrollRange())) { 
      ViewCompat.stopNestedScroll(target, ViewCompat.TYPE_NON_TOUCH); 
     } 
    } 
} 

}

und in unserem AppBarLayout:

 <android.support.design.widget.AppBarLayout 
     ... 
     app:layout_behavior="your.package.FixAppBarLayoutBehavior"> 
     ... 
     </android.support.design.widget.AppBarLayout> 
+0

Dank! Du sparst meinen Tag! –

Verwandte Themen