我在画布上使用了背景图像,并尝试在设备方向更改时相应地调整其大小,有人可以建议我在 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);
}
Run Code Online (Sandbox Code Playgroud)
这个方法是我的代码中扩展Engine 的类的一部分。我的代码非常长,所以我在这里只发布相关部分。
| 归档时间: |
|
| 查看次数: |
2181 次 |
| 最近记录: |