gpt4 book ai didi

android - Recycler View 内部 Recycler View 不滚动

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:35:19 26 4
gpt4 key购买 nike

另一个Recycler View里面有一个Recycler View,都需要垂直滚动。外部 Recycler View 可以正确滚动,但内部 Recycler View 不能。

代码如下:

LinearLayoutManager mLayoutManager = new LinearLayoutManager(ViewActivity.this);
outerRecyclerView.setLayoutManager(mLayoutManager);
ViewAdapter adapter = new ViewAdapter(ViewActivity.this);
outerRecyclerView.setAdapter(adapter);

ViewAdapter如下:

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);
}

我已经在两个回收站 View 上尝试了以下但无法解决问题

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.

最佳答案

Apply this below ontouch listener to inner recycler which is may be in adapter of parent recycler.

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);

关于android - Recycler View 内部 Recycler View 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37423763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com