【问题标题】:Android: Setting padding in a overlay image backgroundAndroid:在覆盖图像背景中设置填充
【发布时间】: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


【解决方案1】:

我刚刚遇到了同样的问题。看看LayerDrawable 上的setLayerInset 方法。它将图层级别作为参数,然后是可绘制对象的左、上、右、下边界的修饰符。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2016-05-30
    • 1970-01-01
    • 2020-05-18
    • 2016-01-14
    • 1970-01-01
    相关资源
    最近更新 更多