我已使用代码
为自定义形状的左侧和上侧添加了边框<?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="#787878" />
</shape>
</item>
<item android:left="1dp" android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#e4e4e4" />
</shape>
</item>
</layer-list>
现在我想为右侧和底部添加不同的边框颜色。但是当我将代码更新为
时<?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="#787878" />
</shape>
</item>
<item android:left="1dp" android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#e4e4e4" />
</shape>
</item>
<item android:right="1dp">
<shape android:shape="rectangle">
<solid android:color="#e4e4e4" />
</shape>
</item>
</layer-list>
当我想要在三面获得边界时,没有任何边界是可见的。我做错了什么?
答案 0 :(得分:4)
在这里你需要添加填充到每个项目,如下所示:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<padding
android:left="2dp"
android:top="2dp" />
<solid android:color="@android:color/holo_red_dark" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding android:right="2dp" />
<solid android:color="@android:color/holo_blue_dark" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<padding android:bottom="2dp" />
<solid android:color="@android:color/white" />
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
希望它真的有用!