Android在drawable XML中的多重描边框

5

我正在尝试在Android的可绘制XML文件中,实现一个矩形上的两种效果:一种是深绿色的外边框,另一种是浅绿色的内边框,中心部分填充有渐变色。目前我的代码如下:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">



<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <stroke android:width="3px" android:color="#477135" />
    </shape>

</item>
<item >
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <gradient android:startColor="#81c557" android:endColor="#539942"
            android:angle="270" />

        <stroke android:width="1px" android:color="#a8d78a" />
    </shape>
</item>

我尝试将android:top="3px" android:bottom="3px"应用于第二个元素,但当我添加right和left属性时,整个内容无法渲染。请注意,这都是在ListView中完成的。

1个回答

1

好的,我相信我用一个解决方法解决了这个问题。虽然不太美观,但它能工作。我设置了一个ImageView,将其背景颜色设置为外部线条颜色,给它一个1dip的填充,然后将ImageView的src设置为drawable,我实现了我想要的效果。话虽如此,我更喜欢能够在layer-list中完成所有操作...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接