Я использую RecyclerView
с GridLayoutManager
и я динамически добавлять новые элементы, которые имеют этот XML:Нет нажмите эффект на CardView в RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
style="@style/cardView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:id="@+id/direction_list_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/icon"
android:layout_gravity="center"
android:padding="8dp"
android:clickable="true" />
<TextView
android:id="@+id/direction_list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dummy text"
android:layout_gravity="center"
android:padding="8dp"
android:clickable="true" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Проблема заключается в том, что я вижу, щелкните влияние на CardView
пункта только тогда, когда я дважды щелкните по нему или сделайте длинный щелчок.
Я попытался поместить LinearLayout
внутри CardView
и сделать в Clickable с android:background="?android:attr/selectableItemBackground"
, но результат остается тем же
Проблема была решена только путем замены RecyclerView с GridView. –
, но что, если я хочу использовать RecyclerView? – temirbek