我创建了CanvasView Object扩展View类,并在我的应用程序的清单中覆盖了configChanged,正如您所看到的,Canvas不会再次正确地重绘。
看起来旋转不会影响Canvas对象。
我已经尝试过再次无效和重新绘制,但它似乎没有任何区别。
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if(canvasBitmap == null){
canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
}else{
Bitmap temporary = Bitmap.createScaledBitmap(canvasBitmap, w, h, true);
canvasBitmap = temporary;
}
mCanvas = new Canvas(canvasBitmap);
draw(mCanvas);
invalidate();
}
我怎样才能保持画布比率和缩放比例显示它在旋转后适合新尺寸?
答案 0 :(得分:0)
我遇到了同样的问题,但使用以下方法修复了它:
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
if(bitMap == null) {
bitMap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
canvas = Canvas(bitMap)
} else {
bitMap = Bitmap.createScaledBitmap(bitMap, w, h, true)
canvas = Canvas(bitMap)
canvas.drawBitmap(bitMap, 0f, 0f, bitMapPaint)
}
}