绘制九补丁到画布(安卓) [英] Drawing Nine Patch onto Canvas (Android)

查看:130
本文介绍了绘制九补丁到画布(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一个九补丁到在Android上一个Canvas对象。似乎有什么奇怪的是,虽然我生成使用draw9patch工具我的九个补丁,该构造NinePatch要求称为块的附加字节数组构造九个补丁。

I'm trying to draw a nine patch onto a Canvas object on the Android. What seems strange is that although I generated my nine patch using the draw9patch tool, the constructor for NinePatch requires an additional byte array called the "chunk" to construct the nine patch.

为什么不是这样简单?什么是块?如果你这样做你自己,你怎么做呢?

Why isn't this simpler? What is the "chunk"? And if you have done this yourself, how did you go about it?

任何帮助AP preciated。

Any help appreciated.

推荐答案

您可以轻松地做到这一点是这样的:

You can easily do it this way:

// Load the image as a NinePatch drawable
NinePatchDrawable npd = (NinePatchDrawable)Resources.getDrawable(R.drawable.my_nine_patch);

// Set its bound where you need
Rect npdBounds = new Rect(...);
npd.setBounds(npbBounds);

// Finally draw on the canvas
npd.draw(canvas);

这篇关于绘制九补丁到画布(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆