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)

Onik
  • 19,396
  • 14
  • 68
  • 91
Mick Byrne
  • 14,394
  • 16
  • 76
  • 91
  • Do you want to implement tiled background with round corners? – teoREtik Feb 08 '12 at 12:17
  • Not exactly what you want but this shows how to implement rounded corners: http://blog.blundell-apps.com/rounded-corners-mapview/ – Blundell Feb 08 '12 at 12:18
  • @teoREtik, yes that's pretty much what I'm trying to achieve. – Mick Byrne Feb 08 '12 at 12:37
  • @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. – Mick Byrne Feb 08 '12 at 12:40
  • Does painting over them not give the illusion that they have been cut off? – Blundell Feb 08 '12 at 12:44
  • @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... – Mick Byrne Feb 09 '12 at 00:29
  • 1
    @Mick hmm bit more complex than I thought, have you looked at Canvas.drawArc() – Blundell Feb 09 '12 at 08:12

2 Answers2

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

1

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

Daniel L.
  • 5,060
  • 10
  • 36
  • 59