我在画布上使用了一个背景图片,并试图在设备方向改变时相应地调整其大小。有人能建议我,在Android上是否可以重新调整画布的尺寸以响应方向的变化。
我在画布上使用了一个背景图片,并试图在设备方向改变时相应地调整其大小。有人能建议我,在Android上是否可以重新调整画布的尺寸以响应方向的变化。
我认为无法调整画布的大小。如果您在画布上使用了一张覆盖整个屏幕的背景图片,那么当屏幕方向改变时,您可以按照以下方式缩放此图片:
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// orientation change
if (_width == width && _height == height) {
_orient = 0;//portrait
this.width = width;
this.height = height;
this._holder=holder;
this.bgBitmap =Bitmap.createScaledBitmap(BitmapFactory
.decodeResource(res, R.drawable.bg), (_holder
.getSurfaceFrame().width()), _holder.getSurfaceFrame()
.height(), false);
} else {
_orient = 1;//landscape
this.width = width;
this.height = height;
his.bgBitmap =Bitmap.createScaledBitmap(BitmapFactory
.decodeResource(res, R.drawable.bg), (_holder
.getSurfaceFrame().width()), _holder.getSurfaceFrame()
.height(), false);
}
super.onSurfaceChanged(holder, format, width, height);
}
这个方法是我代码中扩展引擎类的一部分。由于我的代码非常冗长,因此我仅在此处发布相关部分。