本文介绍了Recycler视图内部的Recycler视图不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
另一个Recycler View内有一个Recycler View,两者都需要垂直滚动. 外部回收者"视图可以正确滚动,但不能内部回收者"视图滚动.
There is a Recycler View inside the other Recycler View.Both needs to scroll vertically. Outer Recycler view is scrolling properly but inner recycler view is not.
这是代码:
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ViewActivity.this);
outerRecyclerView.setLayoutManager(mLayoutManager);
ViewAdapter adapter = new ViewAdapter(ViewActivity.this);
outerRecyclerView.setAdapter(adapter);
ViewAdapter如下:
ViewAdapter is as follows:
public void onBindViewHolder(ViewAdapter.ViewViewHolder holder, int position)
{
//RECYCLER VIEW
//TODO: Inner Recycler view scroll movement
LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
holder.protocolRecyclerView.setLayoutManager(mLayoutManager);
ViewProtocolAdapter adapter = new ViewProtocolAdapter(context);
holder.protocolRecyclerView.setAdapter(adapter);
}
我已经在两个回收站视图上尝试了以下方法,但无法解决问题
I have tried the following on both recycler views but could not solve the problem
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if(rv.getChildCount() > 0) {
View childView = rv.findChildViewUnder(e.getX(), e.getY());
if(childView ==listView) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
rv.requestDisallowInterceptTouchEvent(true);
}
}
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
也尝试过这个:
outerRecyclerView.setNestedScrollingEnabled(true);//Does not make any difference
innerRecyclerView.setNestedScrollingEnabled(true);//Recycler View start scrolling but very slowly and sometimes scrolls the outer one.
推荐答案
RecyclerView.OnItemTouchListener mScrollTouchListener = new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
int action = e.getAction();
switch (action) {
case MotionEvent.ACTION_MOVE:
rv.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
};
innerrecyclerView.addOnItemTouchListener(mScrollTouchListener);
这篇关于Recycler视图内部的Recycler视图不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!