简体   繁体   中英

Android: Background image / imageView for different screens

I want to set a background image to my Activity. I am just using an imageView in a relative Layout and position the other elements as I want them. Now we have a million, or at least quite a few, different screen sizes and densities. I wonder how I can achieve having the right image for all these devices.

I don't want to scale/stretch my image.

The image is in a way that it is lets say 2000 x 2000 pixels (or whatever you like) it doesn't matter what part of this image is displayed. In other words I could crop any needed image size out of this extra large image and display only that portion.

How can I achieve this?

Thanks, A.

Just set your image view android:scaleType="center" and it won't scale or stretch.

Have a look at the scaleType options at the following link. This gives you a decent amount of control over how an image is rendered. http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

Also have a look at the following link. You can provide resources with the same file names in different folders, and the system will choose the most appropriate. This way, you can know more or less what size screen you are targeting with each image and you can create your images at a size that will perform the least cropping (or possibly no cropping at all). http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM