【发布时间】:2017-03-15 04:28:01
【问题描述】:
ViewHolder 基于此布局进行膨胀:
将监听器添加到整个ViewHolder,或者精确到itemView:
userSettingHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
但只有imageView 的第一项才能激活监听器。为什么不是整个项目,没有最后两个'sub'-recycleview?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="66dp">
<ImageView
android:id="@+id/icon"
android:layout_width="66dp"
android:layout_height="66dp"
android:padding="0dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rw1"
android:layout_marginStart="66dp"
android:layout_marginTop="0dp"
android:layout_marginBottom="33dp"
android:layout_height="33dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rw2"
android:layout_marginStart="66dp"
android:layout_marginTop="33dp"
android:layout_marginBottom="0dp"
android:layout_height="33dp"
android:layout_width="match_parent"/>
</RelativeLayout>
【问题讨论】:
-
你能添加你的适配器和项目布局吗?
-
添加了项目布局。
-
看到你的布局,我认为你应该重新定义它。虽然,您可以拥有一个高度为 33dp 的 RecyclerView,但强烈建议您替换为其他视图。
-
顺便说一句,我在您的布局中发现了其他错误。其中之一是您如何在 RelativeLayout developer.android.com/guide/topics/ui/layout/relative.html 中定位视图。另一个是,如果您使用 layout_marginStart,您的应用程序将无法在 RTL 布局中很好地显示。您应该改用 layout_marginLeft。如果您对它们之间的差异有任何疑问,请阅读此链接stackoverflow.com/questions/14904273/…
-
明白,但你还没有回答我的问题。
标签: android android-recyclerview