我需要NinePatchDrawable的帮助:
我的应用程序可以从网络下载主题.除了9-Patch PNG之外,几乎所有的工作都很好.
final Bitmap bubble = getFromTheme("bubble");
if (bubble == null) return null;
final byte[] chunk = bubble.getNinePatchChunk();
if (!NinePatch.isNinePatchChunk(chunk)) return null;
NinePatchDrawable d = new NinePatchDrawable(getResources(), bubble, chunk, new Rect(), null);
v.setBackgroundDrawable(d);
d = null;
System.gc();
Run Code Online (Sandbox Code Playgroud)
getFromTheme()从SD卡加载位图.9-Patch PNG已经编译,这意味着它们包含了所需的块.
我将Bitmap转换为NinePatchDrawable对象的方式似乎正在起作用,因为图像是可拉伸的,而且我画了它.
唯一不起作用的是填充.我已经尝试将填充设置为视图,如下所示:
final Rect rect = new Rect(); // or just use the new Rect() set
d.getPadding(rect); // in the constructor
v.setPadding(rect.left, rect.top, rect.right, rect.bottom);
Run Code Online (Sandbox Code Playgroud)
d.getPadding(rect)应该用填充从块中填充变量rect,不应该吗?但事实并非如此.
结果:TextView(v)不显示9-Patch图像的内容区域中的文本.每个坐标中的填充都设置为0.
谢谢阅读.