I'm trying to create a view in Android
that has rounded corners and also uses a tiled image background (and which appears on top of another view with a tiled background).
I can create a shape drawable for the corners and a bitmap drawable for the tiled image, but I can't see how I can apply them both the same view.
Some things I've attempted:
Nesting the view with the tiled background inside a view with rounded corners - doesn't work, the tiled background just appears on top with square corners
Paint over the corners of the view with rounded corners - this doesn't work because of the tiled background of the view below (otherwise would work fine)
xml file and add an attribute to that TextView, for which you want to add rounded corners. The attribute is android: background=”@drawable/rounded_corner_view”.
Android 12 introduces Rounded Corner API that enables you to get the properties of a screen's rounded corners, such as its center and its radius. As you can see in the image above, with this API you app can be made aware of the screen's rounded corner and avoid truncating the UI elements.
I believe your custom View should define its drawing region with a Path. You could then draw the Path with a paint and shader doing what you want (fill and tile).
http://developer.android.com/reference/android/graphics/Path.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With