简体   繁体   中英

Adding rounded corners to a view?

In my layout, I have two rectangular semi-transparent views in the following configuration:

---------------------|
|      |    B        |
|       -------------|
|  A   |         
|      |
|      |
|      |
|      |
|      |
--------

To make it look nicer, I want to round off the bottom right corner of A and add a curve in the corner where A to B meet like this:

---------------------|
|                    |
|        ------------|
|       /         
|      |
|      |
|      |
|      |
|      |
|      |
|------/ 

Can anyone suggest a way I can do this, preferably without having to use bitmaps (as this means I can change the colors and corner sizes more easily later)?

I know how to round A by itself using a rectangular background drawable and clipping, but I can't think of a nice way to add the corner joining A and B.

If A and B are in a relative layout, you could add a small C view right in the corner, below and left aligned to B, and have it draw the rounding in onDraw().

edit:

in API Demos -> Graphics -> Xfermodes there's an example of how you could draw something with a circle cut out of it (but I have no experience with that).

As far as I know, you can't create corners only from the properties of a view, so I guess you only have two options.

First, use a custom image (maybe a 9-patch can be helpfull to get a single background for the whole thing) but then again, you can't change the color easily.

The other would be to create your own View and override the onDraw() method (take a look here )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM