我嵌套了RecyclerView
,并以此方式禁用了对孩子RecyclerView
的点击,并将此类用作孩子RecyclerView
。
public class MyDisabledRecyclerView extends RecyclerView {
public MyDisabledRecyclerView(Context context) {
super(context);
}
public MyDisabledRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyDisabledRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
return false;
}
我的孩子RecyclerView
位于另一个RecyclerView
项目中,我想在点击孩子RecyclerView
时转到父项RecyclerView
项目单击,因此我禁用了孩子{ {1}},但通过这种方式,子RecyclerView
无法再滚动,我尝试将子RecyclerView
放在RecyclerView
或NestedScrollView
中
但仍然无法正常工作。
答案 0 :(得分:2)
将以下视图添加到您的布局文件中以屏蔽视图层次结构的顶部。
<View
android:id="@+id/recyclerViewDisable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:clickable="true"
android:focusable="true"
android:visibility="gone"/>
设置此视图可见性 View.VISISBLE
当您要禁用回收站视图项单击时。如果要启用项单击然后设置可见性 View.GONE
recyclerViewDisable.setOnTouchListener((view, motionEvent) -> {
recyclerview.onTouchEvent(motionEvent);
return true;
});
这很完美。如果发现可行,则投票给正确答案。
答案 1 :(得分:0)
尝试一下:
childRecyclerView.setNestedScrollingEnabled(false);
答案 2 :(得分:0)
将大多数父项RecyclerView
包装在NestedScrollView
中。
<NestedScrollView
...>
<RecyclerView
.../>
</NestedScrollView>
并在所有recyclerView.setNestedScrollingEnabled(false);
上添加RecyclerView
。
这样,您在Child RecyclerView的滚动中不会有冲突。
用另一个不可点击的RecyclerView
包裹孩子View
。像
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"/>
</FrameLayout>
请注意。
FrameLayout
应该是wrap_content
。RecyclerView
应该和wrap_content
一起nestedScrollingEnabled="false"
。RecyclerView
应该是nestedScrollingEnabled="false"
。 View
上覆盖RecyclerView
应该是match_parent
。 了解
在这里,我们将nestedScrolling false设置为子RecyclerView
。因此,其滚动将被禁用,并且将在父级RecyclerView
中使用wrap_content高度。现在,由于我们在其上添加了一个View
且不可点击,因此子级RecyclerView
将不再可触摸。
答案 3 :(得分:0)
@Override
public void onBindViewHolder(final ChatList_Adapter.ViewHolder holder, final int position) {
holder.name.setText(chanelsList.get(i).getUser().getFirstname()+" "+chanelsList.get(i).getUser().getLastname());
holder.city_recycler_hosts.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, true);
holder.city_recycler_hosts.setLayoutManager(layoutManager);
holder.city_recycler_hosts.addItemDecoration(new VerticalDividerItemDecoration.Builder(context).color(ContextCompat.getColor(context,R.color.lightergray)).margin(0,20).
build());
CityHosts_Adapter adapter=new CityHosts_Adapter(chanelsList.get(i).getUser().getCities(),chanelsList,file,position,pusher
,auth,message_ist);
holder.city_recycler_hosts.setAdapter(adapter);
}
然后在子级RecyclerView中执行与父级RecyclerView click相同的操作,但是我们将父级RecyclerView的位置传递给子级RecyclerView的构造函数适配器,因此,在子级中使用getAdapterPosition
则使用在构造函数中获得的位置