After study related document, I find one simple way is to draw all the component on a prepared bitmap, and then scale it according to target screen ratio.
In EasyMatch App, the bitmap size is 480x800, all components are drawn on it. Before showing the content on the phone's screen, use Matrix to compute the scale factor. The code snippet looked like:
float scaleWidth = screenWidth/480;
float scaleHeight = screenHeight/800;
Bitmap preparedBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
// draw the components on the preparedBitmap
...
// then scale it
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
targetScreenCanvas.drawBitmap(preparedBitmap, matrix, null);
No comments:
Post a Comment