带圆形边框的 Android 表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2387033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android table with round border
提问by xger86x
How can I make a table with a round border, similar to the photo below, in Android?
如何在 Android 中制作与下图类似的带有圆形边框的表格?
回答by Steve Haley
I think Androidbase linked to the wrong question... he asked a similar question recently, and here's the answerI gave him:
我认为 Androidbase 链接到错误的问题......他最近问了一个类似的问题,这是我给他的答案:
You can put a coloured background with rounded corners into a table by using a Shape background. Create such a shape in an XML file, put in your drawables folder.
您可以使用形状背景将带圆角的彩色背景放入表格中。在 XML 文件中创建这样的形状,放入 drawables 文件夹中。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#99FFFFFF"/>
<corners android:radius="30px"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
For example the above creates a semi-transparent white background with 30px rounded corners. You set this to the table by using
例如,上面创建了一个带有 30px 圆角的半透明白色背景。您可以通过使用将其设置为表
android:background="@drawable/my_shape_file"
in the XML file where you defined your table layout.
在您定义表格布局的 XML 文件中。
回答by Richard Le Mesurier
I prefer to use a masking technique - overlay a mask image (any iOS-style background, with a transparent cutout in it) over a standard layout.
我更喜欢使用遮罩技术 - 在标准布局上覆盖遮罩图像(任何 iOS 风格的背景,其中带有透明切口)。
This way, the background of my layout is not linked directly to a bitmap, I can change it very easily.
这样,我布局的背景就不会直接链接到位图,我可以很容易地更改它。
I have an answer explaining that here: Android XML rounded clipped corners
我在这里有一个解释:Android XML rounded clipped corners
回答by vladexologija
I had a similar task recently so I decided to write a library for this purpose. Feel free to use it for your needs... https://github.com/vladexologija/GroupedTextView
我最近有一个类似的任务,所以我决定为此目的编写一个库。随意使用它来满足您的需求... https://github.com/vladexologija/GroupedTextView