简体   繁体   中英

Scaling Image in Android for different screen size

In my application am going to display image from remote data base
In database the image is stored as String(ie)image location
By using image loader class am displaying image in the screen
I want to scale the image according to the screen size ldpi,mdpi,hdpi
How to perform that?

You could use android:layout_width="wrap_content" and android:layout_height="wrap_content" . Then the image always takes as much place as possible.

Or you can create different layouts by creating the following folders in your res directory:

  • layout-ldpi
  • layout-mdpi
  • layout-hdpi

In each folder you can create a custom layout.xml file for each screen resolution.

see first upon the image stored on location must be good in up to match in each resolution means it is in high defination atleast 960*1280 with 480-320 dpi then you can set that image into your imageView through imageloader class then you need to use scaleType="fitXY" property to your image view so it will fit that image as per your image view

now you are thinking why image stored on location want to be atleast 960*1280 with 480-320 dpi ?

cause if it is low resolutional image then when you try to show on hdpi or xhdpi it will get distored on these reoslution thats why hope it will clear your all doubts and it will work for you (it worked for me)

Store the highest quality image in server and handle all other screen related code in your mobile side

use something like this

http://square.github.io/picasso/

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