繁体   English   中英

Android LayerDrawable:如何以编程方式设置图层坐标?

[英]Android LayerDrawable: How to set layer coordinates programmatically?

给定的以下层列表的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代码? 此属性没有设置器。

尝试setLayerInset(layer, leftOffset, topOffset, rightOffset, bottomOffset)

请参阅LayerDrawable文档以获取更多帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM