我有這個項目,其中我有一個大於屏幕尺寸的位圖。我想調整它以準確地適應屏幕。我沒有標題欄,而且處於全屏模式。這是我的非工作代碼:Android - 擬合位圖到屏幕
public class ScopView extends View
{
private Scop thescop;
public ScopView(Context context, Scop newscop)
{
super(context);
this.thescop = newscop;
}
@Override
public void onDraw(Canvas canvas)
{
Bitmap scopeBitmap;
BitmapFactory.Options bfOptions = new BitmapFactory.Options();
bfOptions.inDither = false;
bfOptions.inPurgeable = true;
bfOptions.inInputShareable = true;
bfOptions.inTempStorage = new byte[32 * 1024];
scopeBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.scope, bfOptions);
scopeBitmap.createScaledBitmap(scopeBitmap, SniperActivity.Width, SniperActivity.Height, false);
canvas.drawBitmap(scopeBitmap, SniperActivity.scopx, SniperActivity.scopy, null);
}
}
雖然在這裏createScaledBitmap方法,我使用本身作爲源,並從用於檢索屏首窗口的高度和寬度的活動有一定變數。