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

2

7

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)

Enactment answered 8/2, 2012 at 12:12 Comment(7)
Do you want to implement tiled background with round corners?Profess
Not exactly what you want but this shows how to implement rounded corners: blog.blundell-apps.com/rounded-corners-mapviewDrawing
@teoREtik, yes that's pretty much what I'm trying to achieve.Enactment
@Blundell, thanks for that link. I see what they're doing here - essentially just painting round black corners on top of the view. That would work except in my case I'm trying to place the view on top of another tiled-background view, so the corners actually need to be cut off, rather than just painted over.Enactment
Does painting over them not give the illusion that they have been cut off?Drawing
@Blundel, no because you can only paint over the corners with a solid colour, but the background of the view under the view I'm trying to create also has a tiled image background...Enactment
@Mick hmm bit more complex than I thought, have you looked at Canvas.drawArc()Drawing
B
2

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

Belk answered 31/7, 2012 at 12:30 Comment(0)
A
1

You can check video which contains a way to do it without using clipPath which is not supported with hardware acceleration.

Appellate answered 21/2, 2013 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.