【发布时间】:2015-08-19 03:56:05
【问题描述】:
我已经使用 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>
我的目标是在触摸网格项目时获得这种漂亮的材质波纹效果。 不幸的是,我无法为我的问题找到纯粹的解决方案。 所以我想出了使用this,正如作者所说,解决方法 - 在主 ImageView 顶部添加叠加层 View,并将背景设置为
?attr/selectableItemBackground
把它放到 ImageView 的背景或者父 FrameLayout 背景没有用。
我敢肯定,一定有更好的方法来处理它。
【问题讨论】:
-
试着把它放到
FrameLayout的前台。像这样。android:foreground="?attr/selectableItemBackground". -
@siris_cac 这确实有效,谢谢!知道如何强制它在触摸时产生圆形波浪吗?
-
我不明白。你能解释一下吗?
-
@siris_cac 我已经仔细检查了您的解决方案。碰巧它对某些项目有效,而对其他项目无效。我真的不知道为什么。所以我找到了另一个解决方案,效果很好。将
android:drawSelectorOnTop="true"添加到 GridView 就可以了。
标签: android gridview material-design