开发者

Filling the entire screen in multiple screen resolutions, densities

I want to draw a rectangle that fills the entire screen on all Android phones, all resolution, all screen densities.Everything... :) First from what I understand Canvas.drawRect use as dimensions values in pixel. Hope this is correct. Being new to Android I thought that if I simply write like this it will be sufficient, since at this moment there is no Android device with a resolution higher than 1024x1024 pixels:

ScreenWidth = 1024;
ScreenHeight = 1024;
canvas.drawRect(0,0, ScreenWidth, ScreenHeight, mLoadPaint);

But it seems that on some devices this Rectangle doesn't fill the entire screen. What is strange and I can't explain myself is that this doesn't happens always but at a point in time... Anyway it seems that there is a problem with the code so I would like to change it to look 开发者_JAVA技巧something like this, but now sure it metrics.widthPixels and metrics.heightPixels will solve my problem:

wm = (WindowManager) getSystemService(WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(metrics);
canvas.drawRect(0,0, metrics.widthPixels, metrics.heightPixels, mLoadPaint);

I want to know if this is correct, and if this piece of code will cover all screens, and the rectangle will fill the entire screen. Of course with this approach I will have to take care also of the screen orientation, as it seems that the values are swapped between them when the screen is in Landscape.


You can try canvas.drawColor(int color)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜