【发布时间】:2011-07-13 04:51:27
【问题描述】:
我正在尝试为我的 android 应用程序创建一个动态图标菜单。 图标由 2 个可绘制的、9 个补丁的背景图像组成,上面覆盖有图标图像。
参考overlay two images in android to set an imageview,我有以下代码很好地覆盖了。
Resources res = parent.getResources();
Drawable icon_bg = res.getDrawable(R.drawable.menu_icon_bg);
Drawable icon = res.getDrawable(R.drawable.menu_icon);
// Not working
int int_icon_height = icon.getIntrinsicHeight();
int int_icon_width = icon.getIntrinsicWidth();
Rect rect_icon_bg_bound = new Rect();
rect_icon_bg_bound.left = 0;//(int) Math.round(int_icon_width*-1.5);
rect_icon_bg_bound.right = (int) Math.round(int_icon_width*1.5);
rect_icon_bg_bound.top = 0;//(int)Math.round(int_icon_height*-1.5);
rect_icon_bg_bound.bottom = (int)Math.round(int_icon_height*1.5);
icon_bg.setBounds(rect_icon_bg_bound);
Drawable[] layers = new Drawable[2];
layers[0] = icon_bg;
layers[1] = icon;
LayerDrawable layerDrawable = new LayerDrawable(layers);
ImageView iv_icon_combined = new ImageView(getApplicationContext());
iv_icon_combined.setImageDrawable(layerDrawable);
我现在面临的问题是添加一个填充,以便图标在背景中有一些间距。
希望在这里得到一些启发,在此先感谢。
【问题讨论】:
-
嗨,我仍然坚持这个问题。有没有其他地方可以帮助我解决这个问题?
标签: android image overlay padding