如何将shape drawable和drawable组合成单个drawable

时间:2015-08-14 08:50:48

标签: android android-drawable shapedrawable android-runtime layerdrawable

我在android中以编程方式生成shape drawable和drawable运行时。我需要的是将两个drawable组合成单个drawable。我尝试通过以下方法实现,但似乎没有任何结果。

使用LayerDrawable将两个drawable组合成单个的示例代码

public static LayerDrawable drawCircleWithIcon (Context context, int width, int height, int color,Drawable drawable) {

        ShapeDrawable oval = new ShapeDrawable (new OvalShape ());
        oval.setIntrinsicHeight (height);
        oval.setIntrinsicWidth (width);
        oval.getPaint ().setColor (color);

        Drawable[] layers = new Drawable[2];
        layers[0] = drawable;
        layers[1] = oval;

        LayerDrawable composite1 = new LayerDrawable (layers);

        return composite1;
    }

我传递的论据:

width - width of the circle  
height - height of the circle  
color - color of the circle
drawable - icon that needs to be fit inside the ShapeDrawable (i.e. Round circle inside placed with icon) 

我的要求:

我需要组合两个drawable(一个是ShapeDrawable和drawable)。输出必须如下

enter image description here

请帮助我使用您的解决方案或替代方法将两个drawable合并为一个drawable图标。提前谢谢。

0 个答案:

没有答案