try {
mCanvas = mSurfaceHolder.lockCanvas();
if (mCanvas != null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View v = inflater.inflate(R.layout.clock, null, false);
v.measure(android.view.View.MeasureSpec.makeMeasureSpec(1920, android.view.View.MeasureSpec.AT_MOST), android.view.View.MeasureSpec.makeMeasureSpec(1080, android.view.View.MeasureSpec.AT_MOST));
Bitmap m = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
if (m != null) {
Canvas canvas = new Canvas(m);
canvas.drawColor(Color.WHITE);
v.layout(0, 0, 200, 200);
v.draw(canvas);
canvas.setBitmap(null);
mCanvas.drawBitmap(m, 0, 0, null);
}
}
} finally {
if (mCanvas != null) {
mSurfaceHolder.unlockCanvasAndPost(mCanvas);
}
}
Canvas绘制layout.xml布局
最新推荐文章于 2024-08-29 21:27:52 发布