Search code examples
androidandroid-layoutandroid-viewandroid-imageandroid-shapedrawable

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)


Solution

  • 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