【发布时间】:2018-04-13 19:41:13
【问题描述】:
这是我的 item.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/card_side_margin"
android:layout_marginRight="@dimen/card_side_margin"
app:cardCornerRadius="16dp"
app:cardElevation="8dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="100dp"
android:scaleType="centerCrop"
app:riv_corner_radius_top_left="16dp"
app:riv_corner_radius_top_right="16dp"
tools:src="@drawable/anne_kalbi" />
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/top_rounded_rect" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/white"
android:textSize="@dimen/item_poem_title_size"
tools:text="Anne Kalbi" />
<TextView
android:id="@+id/poet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/white"
android:textSize="@dimen/item_poem_poet_size"
tools:text="Şair: Mehmet Çağan" />
</LinearLayout>
</FrameLayout>
<Button
android:id="@+id/listenBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottom_rounded_rect"
android:gravity="center"
android:text="@string/listen"
android:textColor="#fff" />
</LinearLayout>
</android.support.v7.widget.CardView>
这是我将 onClickListener 添加到 RecyclerView 适配器的 onBindViewHolder 内的 itemView 的地方:
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (itemListener != null)
itemListener.onItemClicked(item, position);
}
});
}
但是,图像部分对点击有反应,但按钮没有反应。它们都在 itemView 中,所以停止按钮的反应是什么?
【问题讨论】:
-
android:clickable="false"进入按钮标签 -
谢谢,@Rahul Kumar
标签: android button android-recyclerview cardview