【发布时间】:2015-11-07 11:17:44
【问题描述】:
我正在以编程方式在 android 中生成形状可绘制和可绘制运行时。我所需要的是将两个drawable组合成一个drawable。我尝试通过以下方法实现,但似乎没有任何效果。
使用 LayerDrawable 将两个可绘制对象组合成单个的示例代码
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)。输出必须如下所示
请帮助我解决将两个可绘制图标合并为一个可绘制图标的替代方法。提前致谢。
【问题讨论】:
-
你为什么不使用 RoundedBitmapDrawable ?
-
感谢您的解决方案。怎么用???
标签: android android-drawable shapedrawable android-runtime layerdrawable