给出了图层列表列表的以下XML代码:
<layer-list>
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/my_color_a" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle" >
<solid android:color="@color/my_color_b" />
</shape>
</item>
</layer-list>为了动态地完成一些事情,我需要以编程的方式将此代码重新构建为LayerDrawable类。这一守则存在于:
ShapeDrawable layer0 = new ShapeDrawable(new RectShape());
ShapeDrawable layer1 = new ShapeDrawable(new RectShape());
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] {layer0, layer1});如何将android:left="5dp"转换为Java代码?这个财产没有设置者。
发布于 2014-09-04 12:45:14
试试setLayerInset(layer, leftOffset, topOffset, rightOffset, bottomOffset)
有关更多帮助,请参考LayerDrawable文档。
https://stackoverflow.com/questions/25665386
复制相似问题