在图像视图上设置波纹效果

问题描述 投票:17回答:5

获得以下图像视图:

<ImageView
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:scaleType="centerCrop"
    app:layout_collapseMode="parallax" 
    android:clickable="true"
    android:focusable="true"
    android:background="?android:attr/selectableItemBackground"/>

如果我不为图像视图设置位图,波纹效果很好。但是一旦我这样设置了位图,波纹效果就消失了:

ImageView iv=((ImageView)rootView.findViewById(R.id.header));
iv.setImageBitmap(myBitmap);

这是我的ripple.xml:

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
                  android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask">
        <shape android:shape="oval">
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>

我猜该位图隐藏了波纹效果,如何使其可见?已经尝试过:

  1. 将android:background更改为android:foreground,这无效。
  2. 在此之上配置另一个透明ImageView,但由于它是透明的,所以未显示波纹。

有什么想法吗?我也看到Lollipop Contacts也做到了。

java android android-5.0-lollipop ripple
5个回答
29
投票

我有一个图片库(由RecyclerViewGridLayoutManager构建)。使用毕加索设置图像。为图像添加波纹我用ImageView包裹了FrameLayout


5
投票

您可以实现,将可绘制对象包装在RippleDrawable中。


4
投票

对于像我这样的懒人:


1
投票

具有圆形效果,请尝试此:


0
投票

[另一种解决方法是用<ripple>包裹图像,将其设置为ImageViewbackground,然后使用tinttintMode来“隐藏” src图像,从而使背景图像可见波纹。

© www.soinside.com 2019 - 2024. All rights reserved.