如何向我在 Android 中用作背景的可绘制对象添加圆角?
我有一个特定的可绘制对象,在我的应用程序中用作背景。它不是纯色。
现在我想给这个可绘制对象添加圆角。
我只发现圆角可用于具有渐变或纯色作为背景的形状,但没有其他可绘制的形状。
是否有另一种简单的方法向可绘制对象添加圆角?
I have a specific drawable that I use as background in my app. It is not a solid color.
Now I want to add rounded corners to this drawable.
I only found the rounded corner available in a shape with a gradient or a solid color as a background but not another drawable.
Is there another easy way of adding rounded corners to a drawable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用AQuery使可绘制或下载的图像变成圆角。
http://code.google.com/p/android-query/wiki/ImageLoading
注意: 这对于执行图像异步任务非常有效,并提供了很多功能。
从此处下载 API: http://code.google .com/p/android-query/downloads/list
代码来实现图像的圆角:
Use AQuery to make Drawable or Downloaded images rounded corners.
http://code.google.com/p/android-query/wiki/ImageLoading
Note : This is very effective in doing asynchronous task with images and provides lots of featres.
Download API from here : http://code.google.com/p/android-query/downloads/list
Code to do rounded Corners of an image :
你能使用“图层列表”绘图来完成你想要的事情吗?它允许您将形状和可绘制图形组合起来,如下所示:
在本例中, shape_overlay 是:
我使用它来在图像上获得“选定”效果。不过,它对我有用,因为相关图像是一个图标,并且背景与包含视图的背景颜色相同(两者都是白色)。
我看到的另一个选项是修改可绘制对象,使其具有圆角。
Could you accomplish what you want using a "layer-list" drawable? It allows you to combine a shape and a graphic drawable like so:
In this case, shape_overlay is:
I'm using this to get a "selected" effect on an image. It works for me, though, because the image in question is an icon and the background is the same color as the containing view's background (both are white).
The other option I see is to modify the drawable so it has rounded corners.
对于我需要它的情况,我让它使用填充渐变且具有圆角的形状。这看起来有点像我想要达到的效果。
如果您有纹理或其他无法使用形状构建的复杂可绘制对象,则似乎您需要向项目中添加带有圆角的可绘制对象。或者自己构建圆角,就像这个 问题<中所解释的那样/a>.
For the case where I needed it I got it working with a shape that was filled with a gradient and had round corners. This looks a bit like the effect I wanted to achieve.
If you have a Texture or some other complex drawable that you can't build with shapes it seems you need to add a drawable with the rounded corners to your project. Or build the round corners yourself like it is explained in this question.
您可以使用您的九个补丁文件创建可绘制的。中心与您当前的背景相匹配,边缘和角落根据需要进行圆化。 Android 文档显示如何创建九个补丁文件< /a> 并且您可以使用绘制九个补丁工具 来构建它。
这就是 SDK 为弹出框等制作圆边、渐变背景样式的方式。
You could create a Nine-patch file with your drawable. With the center matching your current background and the edges and corners rounded, as needed. The Android documentation shows how to create Nine-patch files and you may be able to use the Draw nine-patch tool to build it.
This is how the SDK makes rounded-edge, gradient background styles for popup boxes and such.