[英]NestedScrollView not fling with Recyclerview inside
I have a layout like that: 我有这样的布局:
<NestedScrollView>
<RecyclerView> // vertical recycler view
<RecyclerView/> // horizontal recycler view
<RecyclerView/>
<RecyclerView/>
...
<RecyclerView>
</NestedScrollView>
The result looks like Google play store: 结果看起来像Google Play商店:
And I disabled NestedScrolling in horizontal Recycler
view: 我在horizontal Recycler
视图中禁用了NestedScrolling:
horizontalRecyclerView.setHasFixedSize(true);
horizontalRecyclerView.setNestedScrollingEnabled(false);
The vertical recyclerview
does not scroll fling, whenever ACTION_UP
happen, the vertical recyclerview
also stop scrolling. vertical recyclerview
ACTION_UP
不会滚动,每当ACTION_UP
发生时, vertical recyclerview
ACTION_UP
也会停止滚动。
How can I nest vertical recyclerview
inside nestedscrollview
, and horizontal recyclerview
inside vertical recyclerview
like Playstore and keep the scroll smooth. 我怎么能窝vertical recyclerview
内nestedscrollview
和horizontal recyclerview
内vertical recyclerview
像Play商店中,并保持滚动顺畅。
Using custom nested scroll view of @vrund purohit (code below), and disabled nestedscroll both vertical and horizontal recyclerview: 使用@vrund purohit的自定义嵌套滚动视图(下面的代码),并禁用nestedscroll垂直和水平recyclelerview:
verticalRecyclerView.setNestedScrollingEnabled(false);
... add each horizontal recyclerviews:
horizontalRecyclerView.setNestedScrollingEnabled(false);
使用以下代码进行平滑滚动:
ViewCompat.setNestedScrollingEnabled(recyclerView, false);
I had this same problem and I solved this issue by customizing NeatedScrollView
. 我有同样的问题,我通过自定义NeatedScrollView
解决了这个问题。
Here is the class for that. 这是上课。
MyNestedScrollView MyNestedScrollView
public class MyNestedScrollView extends NestedScrollView {
@SuppressWarnings("unused")
private int slop;
@SuppressWarnings("unused")
private float mInitialMotionX;
@SuppressWarnings("unused")
private float mInitialMotionY;
public MyNestedScrollView(Context context) {
super(context);
init(context);
}
private void init(Context context) {
ViewConfiguration config = ViewConfiguration.get(context);
slop = config.getScaledEdgeSlop();
}
public MyNestedScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public MyNestedScrollView(Context context, AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context);
}
private float xDistance, yDistance, lastX, lastY;
@SuppressWarnings("unused")
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final float x = ev.getX();
final float y = 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:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance) {
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
public interface OnScrollChangedListener {
void onScrollChanged(NestedScrollView who, int l, int t, int oldl,
int oldt);
}
private OnScrollChangedListener mOnScrollChangedListener;
public void setOnScrollChangedListener(OnScrollChangedListener listener) {
mOnScrollChangedListener = listener;
}
@Override
protected void onScrollChanged(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. 快乐的编码。
在RecyclerView xml中添加:
android:nestedScrollingEnabled="false"
[RESOLVED] I have same issue with Horizontal recycleview. [已解决]我对Horizontal recycleview也有同样的问题。 Change Gradle repo for recycleview 更改Gradle repo for recycleview
compile 'com.android.support:recyclerview-v7:23.2.1' Write this: linearLayoutManager.setAutoMeasureEnabled(true); 编译'com.android.support:recyclerview-v7:23.2.1'写这个:linearLayoutManager.setAutoMeasureEnabled(true);
Fixed bugs related to various measure-spec methods in update 修复了更新中与各种measure-spec方法相关的错误
Check http://developer.android.com/intl/es/tools/support-library/features.html#v7-recyclerview 查看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". 我发现了23.2.1库的问题:当item为match_parent时,回收视图填充要查看的完整项目,请始终使用最小高度或“wrap_content”。
Thanks 谢谢
I've solved the issue by using below code: 我使用下面的代码解决了这个问题:
myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false){
@Override
public boolean canScrollHorizontally() {
return true;
}
@Override
public boolean canScrollVertically() {
return true;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.