Unlimited ripples and Android background

can I create a RippleDrawable, defining unlimited ripple and at the same time the background color? I tried everything, but when I determine the shape and its color, the ripples are no longer limited. Also on this page https://developer.android.com/reference/android/graphics/drawable/RippleDrawable.html there is no link to add unlimited ripple in the form.

I tried this list of layers, but the result is terrible

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <ripple android:color="@color/android_l_light_gray"> </ripple> </item> <item> <shape android:shape="rectangle"> <solid android:color="@color/android_l_dark_gray" /> </shape> </item> </layer-list> 

that's what i get enter image description here

+6
source share
1 answer

First of all, keep in mind that the layer-list drawable works like a FrameLayout , it adds up the item as it appears, so if you want your ripple to be in front, just move it down.

 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/android_l_dark_gray"/> </shape> </item> <item> <ripple android:color="@color/android_l_light_gray"/> </item> </layer-list> 

Produces something like

layer list ripple on top

Now do you notice how it is “clipped” by other buttons? this is actually overwork, it is because of the drawing order, the background of other views is drawn on top, and not that the ripples are actually cropped, so I can come up with several solutions for your specific layout:

a. Get ViewGroup layer-list and use only ripple as the button background, use shape or color as the background of the ViewGroup , creating:

ripple only

Note that you lost the grid as an effect due to a different background, but look at the other candy pads and you will notice that they don't have grid dividers if you still want them to use your ViewGroup to paint them.

b. Use / draw the ripples as the foreground / overlay / drawableTop background and the other as the background, but I think you might run into a similar problem with the drawing order as before.

with. I had one more in mind, but I just forgot, it can come back as a dream ¯ \ _ (ツ) _ / ¯

Check out the Calculator from AOSP , you can take CalculatorPadLayout for your grid or just find out how they do it :)

+18
source

Source: https://habr.com/ru/post/978476/


All Articles