【发布时间】:2015-12-10 00:06:28
【问题描述】:
我希望 RecyclerView 中的项目在按下时有触摸反馈或涟漪,但它们似乎不起作用,我认为这是因为复选框。
波纹只在长按时显示,但简单按不会显示。
有人可以帮我解决它吗?提前致谢。
PD:我使用的是 ListView,项目布局父级是 LinearLayout。涟漪工作正常。移动到 RecyclerView 后,项目波纹不起作用。我再次尝试使用 LinearLayout,但仍然无法正常工作。
这是布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/requestCard"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:maxHeight="64dp"
android:maxWidth="64dp"
android:padding="@dimen/lists_padding"
android:src="@drawable/ic_launcher"
tools:ignore="ContentDescription"/>
<TextView
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/imgIcon"
android:layout_toRightOf="@+id/imgIcon"
android:ellipsize="end"
android:maxLength="@integer/request_text_length"
android:maxLines="1"
android:padding="@dimen/lists_padding"
android:textSize="@dimen/abc_text_size_large_material"
tools:text="App Name"/>
<CheckBox
android:id="@+id/chkSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false"
android:padding="@dimen/lists_padding"/>
</RelativeLayout>
【问题讨论】:
-
在项目的根元素中添加 android:descendantFocusability="blocksDescendants"。
-
@GabrieleMariotti 已经做到了。还是行不通。更新了布局文件。
-
我不太确定,但这可能会发生,因为视图组中的视图覆盖了您的连锁反应。所以它就在那里,但你看不到它。所以我最终为波纹添加了一个额外的简单视图(具有 match_parent 宽度和高度)。您可能想尝试一下。
标签: android android-layout android-recyclerview