【发布时间】:2015-08-26 01:58:10
【问题描述】:
我使用显示条目列表的 RecyclerView。每个条目都承载另一个 RecyclerView,它是一个图像列表。
我现在想让这个嵌套的 RecyclerView 可点击,不是它的项目,而是整个视图。
我怎样才能做到这一点?
问题:
- 为嵌套 RecyclerView 的主视图设置 onClickListener 确实有效,但前提是我在 RecyclerView 本身之外单击
- 单击嵌套的 RecyclerView 不会将单击传递给父视图(我什至尝试将 clickable、focusable、focusableIntouch 设置为 false,但触摸不是委托而是由嵌套的 RecyclerView 消耗...李>
这是包装适配器的视图:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="0dp"
android:layout_margin="5dp"
android:foreground="?android:attr/selectableItemBackground" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rlTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Datum"
android:textStyle="bold"
android:id="@+id/tvDate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Info"
android:id="@+id/tvInfo" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvData"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:layout_below="@+id/rlTop"
android:layout_width="match_parent"
android:layout_height="68dp"
android:scrollbars="horizontal" />
</RelativeLayout>
</android.support.v7.widget.CardView>
【问题讨论】:
-
你想让内部回收站视图是水平的吗?
-
是的。它显示了一排图片...
-
我没有完全理解。你想要某种 onItemClickListener 吗?整行?
-
正是...我希望整行都可以点击。将
onClickListener设置为行有效,但嵌套RecyclerView消耗的区域没有反应,只有视图的其余部分...
标签: android onclicklistener android-recyclerview