Android - 如何在GridView项目上获得涟漪效应?

end*_*san 1 android gridview material-design

我使用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>
Run Code Online (Sandbox Code Playgroud)

我的目标是在触摸网格项时获得这种漂亮的材质波纹效果.不幸的是,我无法找到解决问题的纯解决方案.所以我提出使用,正如作者所说,解决方法 - 在主ImageView的顶部添加叠加视图,并将背景设置为

?attr/selectableItemBackground

将它放到ImageView的背景或父FrameLayout背景不起作用.

我敢肯定,必须有更好的方法来处理它.

end*_*san 9

android:drawSelectorOnTop="true" 在GridView中做了这个伎俩