Nestedscrollview Not Fling With Recyclerview Inside
Solution 1:
Use below code for smooth scroll:
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
Solution 2:
Add this in your RecyclerView xml:
android:nestedScrollingEnabled="false"
Solution 3:
I had this same problem and I solved this issue by customizing NeatedScrollView
.
Here is the class for that.
MyNestedScrollView
publicclassMyNestedScrollViewextendsNestedScrollView {
@SuppressWarnings("unused")privateint slop;
@SuppressWarnings("unused")privatefloat mInitialMotionX;
@SuppressWarnings("unused")privatefloat mInitialMotionY;
publicMyNestedScrollView(Context context) {
super(context);
init(context);
}
privatevoidinit(Context context) {
ViewConfigurationconfig= ViewConfiguration.get(context);
slop = config.getScaledEdgeSlop();
}
publicMyNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
publicMyNestedScrollView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
privatefloat xDistance, yDistance, lastX, lastY;
@SuppressWarnings("unused")@OverridepublicbooleanonInterceptTouchEvent(MotionEvent ev) {
finalfloatx= ev.getX();
finalfloaty= ev.getY();
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
// This is very important line that fixes
computeScroll();
break;
case MotionEvent.ACTION_MOVE:
finalfloatcurX= ev.getX();
finalfloatcurY= ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance) {
returnfalse;
}
}
returnsuper.onInterceptTouchEvent(ev);
}
publicinterfaceOnScrollChangedListener {
voidonScrollChanged(NestedScrollView who, int l, int t, int oldl,
int oldt);
}
private OnScrollChangedListener mOnScrollChangedListener;
publicvoidsetOnScrollChangedListener(OnScrollChangedListener listener) {
mOnScrollChangedListener = listener;
}
@OverrideprotectedvoidonScrollChanged(int l, int t, int oldl, int oldt) {
super.onScrollChanged(l, t, oldl, oldt);
if (mOnScrollChangedListener != null) {
mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
}
}
}
Happy coding.
Solution 4:
[RESOLVED] I have same issue with Horizontal recycleview. Change Gradle repo for recycleview
compile 'com.android.support:recyclerview-v7:23.2.1' Write this: linearLayoutManager.setAutoMeasureEnabled(true);
Fixed bugs related to various measure-spec methods in update
Check http://developer.android.com/intl/es/tools/support-library/features.html#v7-recyclerview
I have found issue with 23.2.1 library: When item is match_parent recycle view fill full item to view, please always go with min height or "wrap_content".
Thanks
Solution 5:
I've solved the issue by using below code:
myRecyclerView.setLayoutManager(newLinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false){
@OverridepublicbooleancanScrollHorizontally() {
returntrue;
}
@OverridepublicbooleancanScrollVertically() {
returntrue;
}
});
Post a Comment for "Nestedscrollview Not Fling With Recyclerview Inside"