java - Set ripple effect on Image View -
got following image view:
<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"/>
ripple works great if don't set bitmap image view. once set bitmap this, ripple effect gone:
imageview iv=((imageview)rootview.findviewbyid(r.id.header)); iv.setimagebitmap(mybitmap);
this 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>
i guess bitmap hides ripple effect, how can make visible? tried:
- changing android:background android:foreground, didn't work.
- configuring transparent imageview on top of one, since transparent ripple wasn't shown.
any ideas? i've seen lollipop contacts made well.
i have image gallery (built recyclerview
, gridlayoutmanager
). image set using picasso. add ripple image i've wrapped imageview
framelayout
. item layout is:
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="120dp" android:foreground="@drawable/ripple" android:clickable="true" android:focusable="true" > <imageview android:id="@+id/grid_item_imageview" android:layout_width="match_parent" android:layout_height="120dp" android:layout_gravity="center" android:scaletype="centerinside" /> </framelayout>
note android:foreground
. it's not same android:background
. i've tried without android:clickable="true"
, android:focusable="true"
, works, doesn't hurt.
then add ripple.xml
drawable res/drawable
:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:shape="rectangle"> <solid android:color="#7ff5ac8e" /> </shape> </item> <item> <shape android:shape="rectangle"> <solid android:color="@android:color/transparent" /> </shape> </item> </selector>
note shows semi-transparent color on top of image when item selected (for devices version older android 5.0). can remove if don't want it.
then add ripple.xml
drawable ripple res/drawable-v21
:
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/coral"> </ripple>
you can use default ripple effect instead of custom ripple.xml
, it's difficult see on top of image because it's grey:
android:foreground="?android:attr/selectableitembackground"
Comments
Post a Comment