简体   繁体   English

在视图中添加圆角?

[英]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: 为了使它看起来更好,我想舍入A的右下角,并在A到B相交的角上添加一条曲线,如下所示:

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

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. 我知道如何使用可绘制和修剪的矩形背景自行对A进行圆角处理,但我想不出一种添加将A和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(). 如果A和B在相对布局中,则可以在角落的右下方,左下方与B对齐添加一个小的C视图,并在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). API演示->图形-> Xfermodes中,有一个示例,您可以用它切出的圆画出一些东西(但我对此没有经验)。

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. 首先,使用自定义图像(可能只有9个补丁可以使整个背景变成单个背景),但是再说一遍,您就不容易更改颜色。

The other would be to create your own View and override the onDraw() method (take a look here ) 另一种是创建自己的View并覆盖onDraw()方法( 在此处查看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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