Tho*_*Vos 15 java android android-layout android-recyclerview
是否可以使RecyclerView不可点击?我想要这个,因为我RecyclerView只是在一个可点击的内容中 显示了一些小图标CardView.因此,如果有人点击图标,它应该只是点击(和动画)父母CardView.
我尝试过以下方法:
recyclerView.setClickable(false);recyclerView.setFocusable(false);RecyclerView并onTouchEvent(MotionEvent)返回false.itemView.setClickable(false);在RecyclerView适配器中使用.这样做,点击发送给父母.但是,现在RecyclerView不再可滚动了.clickable="false",focusable="false",focusableInTouchMode="false"虚增列表项XML.(见评论@Ibrahim)recyclerView#setLayoutFrozen(true)和itemView.setClickable(false);.这有效,但与#4有同样的问题.有任何想法如何禁用和传递RecyclerView到父视图的点击事件?请注意,RecyclerView仍然需要可滚动(水平).
编辑:
User @ c.dunlap建议将OnClick监听器设置为图标,并将点击"重定向"到父级的点击操作.这可以工作,但父视图上不会有点击动画.如果有人在RecyclerViewitemView 外部点击 - 但仍在(例如ItemDecoration填充)内部 - 未检测到点击.所以不幸的是,这不是一个解决方案.
您应该扩展父视图并拦截点击,因此recyclerview不会收到它。
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true;
}
Run Code Online (Sandbox Code Playgroud)
归功于:解决方案
小智 -2
我遇到了同样的问题,在我尝试了更多的事情之后,我在 recyclerview 上又使用了一种布局。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layoutwidth="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
之后你就可以看到“LinearLayout”了。这100%有效。
| 归档时间: |
|
| 查看次数: |
5341 次 |
| 最近记录: |