Android ApiDemos示例解析(84):Graphics->UnicodeChart
本例没有介绍什么新知识,只是指屏幕上每页显示256个字符,使用“左”,“右”方向键来翻页。
每页绘制的代码如下:
[java]
private void drawChart(Canvas canvas, int base) {
char[] chars = mChars;
for (int i = 0; i < 256; i++) {
int unichar = base + i;
chars[i] = (char)unichar;
canvas.drawText(Integer.toHexString(unichar),
computeX(i), computeY(i), mLabelPaint);
}
canvas.drawPosText(chars, 0, 256, mPos, mBigCharPaint);
}
private void drawChart(Canvas canvas, int base) {
char[] chars = mChars;
for (int i = 0; i < 256; i++) {
int unichar = base + i;
chars[i] = (char)unichar;
canvas.drawText(Integer.toHexString(unichar),
computeX(i), computeY(i), mLabelPaint);
}
canvas.drawPosText(chars, 0, 256, mPos, mBigCharPaint);
}
通过(char) 将整数强制转化为字符,然后调用drawPosText绘制字符串。
作者:mapdigit
补充:移动开发 , Android ,