Android - image in the center in all screen resolutions

Now I am developing an Android application using SDK 1.5 and a testing application on HTC Hero, its firmware is Android 1.5.

Let me come to the actual point: in the application I have an image to display the image (image resolution 320 * 480), now the image is viewing the image in full screen mode, but when I try to check it on HTC EVO 4G (with a resolution of 480 * 800), The image becomes stretched.

So what I like to do is display a resolution of 320 * 480 pixels on all mobile networks with a screen resolution? I mean to say if the mobile phone has a higher resolution (i.e. 480 * 800, 480 * 854 or more) than the image should be displayed in the "Center" part of the screen.

Thus, the image is displayed in the Center in all screens (without stretching or cutting), except for 320 * 480, what attributes should I set?

+6
android android-imageview imageview
source share
1 answer

Just set the scaleType attribute of your ImageView. Possible values ​​here: ImageView.ScaleType You can use CENTER .

In addition, you are faced with another problem: you need to provide an hdpi image in addition to your mdpi image so that your mdpi image does not automatically expand to hdpi on Android. More details here: http://developer.android.com/guide/topics/resources/providing-resources.html

Edit: Oh, and I almost forgot: the drawable-mdpi and drawable-hdpi folders are only possible if you are creating your own project against Android 1.6. So you have to set your minSdkVersion to 3 and your targetSdkVersion to 4, and put your images in a regular targetSdkVersion folder so that Android 1.5 catches up. Check out this video from Google I / O 2010 to find out more: Broadband for all Android devices .

+5
source share

All Articles