问题
I have a tablet motorola xoom with 1280*800
I have one image in my drawable folder in my project and when i checked the size of the that image its showing 1280*755
but when i used this image in my project.
And debugging it to know the size of it showing 853*503
and obviously it will not fit into the tablet.i have attached the picture here also.
I am getting the width and height by using following code.
BitmapDrawable bd=(BitmapDrawable)this.getResources().getDrawable(R.drawable.fish_normal);
int height=bd.getBitmap().getHeight();
int width=bd.getBitmap().getWidth();
回答1:
I think you are using images in hdpi folder.
//for hdpi
853 * 240 / 160 =1279.5
503 * 240 / 160 = 754.5
// 750 + 50 remaining 50 px for bottom bar
1280 * 160/160-1280 //for mdpi
Therefore generalised size of your resources (assuming they are full screen):
ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
回答2:
First of all, Honeycomb and Ice Cream Sandwich devices has the soft button bar in the bottom of the screen which takes up some of the screen real estate. In your case it seems like it takes 45 px (800 - 755).
Then you have to take the density into account. I'm guessing it is 1.5 for the Motorola Xoom. You can check this by running:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
Log.d("TAG", dm.density);
This means that to fill the screen you have to divide the screen resolution by the density to get the size you need for the image.
来源:https://stackoverflow.com/questions/9224173/tablet-resolution-issue