获得以下图像视图:
<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>
我猜该位图隐藏了波纹效果,如何使其可见?已经尝试过:
有什么想法吗?我也看到Lollipop Contacts也做到了。
我有一个图片库(由RecyclerView
和GridLayoutManager
构建)。使用毕加索设置图像。为图像添加波纹我用ImageView
包裹了FrameLayout
您可以实现,将可绘制对象包装在RippleDrawable中。
对于像我这样的懒人:
具有圆形效果,请尝试此:
[另一种解决方法是用<ripple>
包裹图像,将其设置为ImageView
的background
,然后使用tint
和tintMode
来“隐藏” src
图像,从而使背景图像可见波纹。