java如何为列表项动态设置boder颜色?
我有一个列表视图,里面有RelativeLayout元素。我想根据项目的数据为每个项目的右边框设置不同的颜色。我知道我可能需要这样的东西来创建边界:
<layer-list xmlns:安卓="http://schemas.安卓.com/apk/res/安卓">
<item>
<shape 安卓:shape="rectangle">
<stroke 安卓:width="2dp" 安卓:height="2dp"
安卓:color="#FF0000" />
<solid 安卓:color="#000000" />
<padding 安卓:left="1dp" 安卓:top="1dp" 安卓:right="1dp"
安卓:bottom="1dp" />
<corners 安卓:radius="1dp" 安卓:bottomRightRadius="5dp"
安卓:bottomLeftRadius="0dp" 安卓:topLeftRadius="5dp"
安卓:topRightRadius="0dp" />
</shape>
</item>
</layer-list>
但我不知道如何为每个元素设置颜色
# 1 楼答案
你需要你的own custom Adapter和XML-Drawables来显示你需要的形状。在适配器的getView-Method中,动态地将drawable添加到返回的视图中。希望有帮助