NinePatchDrawable does not get padding from chunk

后端 未结 4 1428
鱼传尺愫
鱼传尺愫 2021-02-06 03:59

I need help with NinePatchDrawable:

My app can download themes from the network. Almost all things work fine, except 9-Patch PNGs.

final Bitmap bubble =          


        
4条回答
  •  无人共我
    2021-02-06 04:35

    I've never seen an example where the Padding isn't included as part of the 9-patch like so:

    enter image description here

    To do this you should first construct a NinePatch and then create you're Drawable from it:

    NinePatch ninePatch = new NinePatch(bitmap, chunk, srcName);
    NinePatchDrawable d = new NinePatchDrawable(res, ninePatch);
    

    However, you seem to be constructing your Drawable with an empty rectangle:

    NinePatchDrawable d = new NinePatchDrawable(getResources(), bubble, chunk, new Rect(), null);
    

    If you want to programatically specify the padding try this:

    Rect paddingRectangle = new Rect(left, top, right, bottom);
    NinePatchDrawable d = new NinePatchDrawable(getResources(), bubble, chunk, paddingRectangle, null);
    

提交回复
热议问题