创建一个只有两个圆角边缘的矩形
我可以创建一个所有边缘均为圆形的矩形形状。然而,我想要的是一个矩形,只有两个边缘是圆形的。这可能吗?
我本质上是在拼凑一个 ListView,它看起来像一个带有圆形边缘的气泡。我希望添加一个两个顶部边缘呈圆形的页眉和一个两个底部边缘呈圆形的页脚。
I can create a shape that is a rectangle with all edges rounded. However, what I'm wanting is a rectangle shape with only 2 of the edges rounded. Is this possible?
I'm essentially hacking together a ListView that looks like a bubble with rounded edges. I'm looking to add a header that has the two top edges rounded and a footer with the two bottom edges rounded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这段代码(从?)Android 版本 2.2 开始工作。参考文档,代码应该看起来像像下面这样:
This code is just working (since?) Android version 2.2. Referring to the documentation, the code should look like the following:
您可能会发现这很有帮助。
You might find this helpful.
我将
android:radius
属性更改为android:topRightRadius
和android:topLeftRadius
I changed the
android:radius
attribute toandroid:topRightRadius
andandroid:topLeftRadius
我认为最好的(根据我对你的问题的理解)是创建一个 9patch 图像并将其用作背景 - 可以定义为根据需要拉伸并在 XML 级别设置,从而节省一些代码工作
I think the best (to my understanding of your question) is to create a 9patch image and use it as background - can be defined to stretch as you need and set at the XML level saving some code work
使用上面的代码
Use the above code
我会尝试绘制一个圆角矩形,然后绘制两个与圆角矩形的角半径相同大小的附加矩形,并将它们放置在您不想圆角的角上。
例如,一个半径为 15px 的圆角矩形,以及两个 15x15px 的常规矩形,放置在不应圆化的圆角矩形的角上。
编辑:重新阅读您的问题,您最好为列表视图的顶部和底部制作一个简单的 9 补丁图像。它们可以以这种方式拉伸到任何尺寸,而无需像素化。不过,这需要您事先创建图像,并且使用矩形形状进行操作会更容易在以后的代码中进行修改。然而,9 个补丁的方式就不那么麻烦了。
I would try drawing a rounded rectangle, and then two additional rectangles of the same size as the rounded rectangle's corner radius, and place them in the corners that you don't want to be rounded.
So for example, a rounded rectangle with a radius of 15px, and two regular rectangles 15x15px, placed into the corners of the rounded rectangle that should not be rounded.
EDIT: Re-reading your question, you might be better off making a simple 9-patch image for the top and bottom of your listview. They would stretch to any size that way without pixelization. That would require you to create the images beforehand, though, and doing things with the rectangle shapes would be easier to modify in code later. However, the 9-patch way would be less of a hack.
绘制一个圆角矩形,然后在圆角矩形上绘制一个具有相同颜色的普通矩形。
Draw a rounded rectangle and then draw a normal rectangle over the rounded one with the same color.