在可绘制的 xml 中的 android 视图上创建边框,在 3 边?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10150092/
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
Create borders on a android view in drawable xml, on 3 sides?
提问by user717572
I want to make a drawable for my Android button, defined as drawable. I found I could set all the borders by using a rectangle, but I got kinda stuck when I wanted it on three sides. I want for example have either the top or the bottom open.
我想为我的 Android 按钮制作一个 drawable,定义为 drawable。我发现我可以使用矩形设置所有边框,但是当我想要它在三个边上时我有点卡住了。例如,我想打开顶部或底部。
Could anyone show me how to do this?
谁能告诉我如何做到这一点?
回答by Shubhayu
Try doing this, though I saw it on some other post
尝试这样做,虽然我在其他帖子中看到过
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#FFFFFF" />
<padding
//android:bottom="10dp" Remove this to avoid seeing the bottom border
android:left="10dp"
android:right="10dp"
//android:top="10dp" Remove this to avoid seeing the top border
/>
<corners android:radius="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
<solid android:color="#666666" />
</shape>
</item>
</layer-list>
回答by Dan Cartoon
If anyone is running into issues regarding padding taking effect in the accepted answer, try taking a look at: https://stackoverflow.com/a/11006931. That solution uses position attributes on the tags to achieve the same effect.
如果有人在接受的答案中遇到有关填充生效的问题,请尝试查看:https: //stackoverflow.com/a/11006931。该解决方案使用标签上的位置属性来实现相同的效果。
I was having trouble using the accepted answer here while creating drawables for use in an ActionBar, and the linked approach worked for me.
在创建用于 ActionBar 的可绘制对象时,我在使用这里接受的答案时遇到了问题,链接方法对我有用。
回答by Thriveni
This might help you.
这可能对你有帮助。
I The border on Three sides of the XML
I XML 三边的边界
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="0dp" android:right="0dp" android:top="0dp" android:bottom="-5dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:radius="0dp" />
<stroke android:width="3dp" android:color="#000000" />
</shape>
</item>
</layer-list>