Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to create a view with rounded corners and a tiled image background?

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)

like image 373
Mick Byrne Avatar asked Feb 08 '12 12:02

Mick Byrne


People also ask

How do I round corners in Android?

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”.

What is rounded app on Android?

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.


1 Answers

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

like image 71
smokeandmirrors Avatar answered Sep 28 '22 11:09

smokeandmirrors