【问题标题】:Android - How to get ripple effect on GridView items?Android - 如何在 GridView 项目上获得涟漪效应?
【发布时间】: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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 谢谢,但我知道这一点。我一直在寻找让它在 Lollipop 上工作的方法。
    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多