Android - 如何对 GridView 项目产生连锁反应?

Android - How to get ripple effect on GridView items?

我已经使用 GridView 实现了图库。网格项目的布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="blocksDescendants" >

    <ImageView
        android:id="@+id/media_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/thumbnail_for_image"
        android:scaleType="centerCrop" />

    <View
        android:id="@+id/overlay_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="?attr/selectableItemBackground" />
</FrameLayout>

我的目标是在触摸网格项时获得这种漂亮的 material 涟漪效果。 不幸的是,我无法为我的问题找到纯粹的解决方案。 所以我想到了使用 this,正如作者所说,解决方法 - 在主要 ImageView 之上添加叠加层 View,并设置

的背景

?attr/selectableItemBackground

将其置于 ImageView 的背景或父 FrameLayout 背景中无效。

我敢肯定,一定有更好的方法来处理它。

如果您希望在棒棒糖之前的版本中支持此波纹,我建议您使用像 The ones here 这样的波纹库。我想使用 ?attr/selectableItemBackground 不会让你在 pre-L 机器人上产生涟漪。

android:drawSelectorOnTop="true" 在 GridView 中成功了