Android, Canvas and Screens
I think I've got quiet a common problem in regards to Android development, but cant seem to find the answer I'm looking for.
If I make a canvas on Photoshop 800x480px (240ppi) and make a logo within that canvas that is 282 x 121px, I cant understand why when I display the image it takes up 3/4 of the screen in my emulator with the same 800x480px.
The code I use to display the logo is the following
Bitmap logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
//in the onDraw
canvas.drawBitmap(logo开发者_如何学编程, 0, 0, null);
Thanks in advance!
Possible Solution
Not sure if this is the best way to do things and would appriciate any feedback, I came across this solution (typically when you've already posted a question :D ) was to code the image as follows:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
//Load images
logo = BitmapFactory.decodeResource(getResources(), R.drawable.logo, options);
The image was probably only taking up 3/4 of the screen in the emulator because of the pre-scaling android sometimes does.
Check out this article on how to handle multiple resolutions and screen sizes.
You could try placing the drawable into a 'res/drawable-mdpi/' directory or a 'res/drawable-ldpi/' to differentiate between medium density and low density screens. Another option is to place it in a 'res/drawable-nodpi/' directory to prevent any pre-scaling. I've even placed some images in the 'res/raw' folder to get the same effect.
However, if your current method works, go for it!
精彩评论