2012-08-23 39 views

回答

7

您可以通过使用layerlist并用填充搞乱实现这一目标。你需要3个要素:

1:border.xml形状,这仅仅是一个固体形状的边框的颜色:border.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ff0000"/> 
</shape> 

2: '内部' 形状,你想边框出现的形状:inner.xml

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#00ff00"/> 
</shape> 

3:一个图层列表,它将把这两个放在海誓山盟之上。您可以通过设置填充的内部形状创建边框:layerlist.xml

<?xml version="1.0" encoding="UTF-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/border"/> 
<item android:drawable="@drawable/inner" 

这里指定您希望有一个行程(顶部,左侧,右侧和底部)

android:top="3dp" android:right="0dp" android:bottom="3dp" 
android:left="3dp" /> 

将此设置为TextView,Layout等的背景(您希望笔画出现的位置)

或者只是创建带有边框的9Patch图像。

+0

如何喜欢这个http://stackoverflow.com/questions/40322955/android-shape-border-with-gradient-and-middle-transparent? – Suman