简体   繁体   English

在Android中缩放图像以适合不同的屏幕尺寸

[英]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 我想根据屏幕尺寸ldpi,mdpi,hdpi缩放图像
How to perform that? 如何执行?

You could use android:layout_width="wrap_content" and android:layout_height="wrap_content" . 您可以使用android:layout_width="wrap_content"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: 或者,您可以通过在res目录中创建以下文件夹来创建不同的布局:

  • layout-ldpi 版面配置
  • layout-mdpi 布局-mdpi
  • layout-hdpi 布局-hdpi

In each folder you can create a custom layout.xml file for each screen resolution. 在每个文件夹中,您可以为每个屏幕分辨率创建一个自定义layout.xml文件。

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 首先查看存储在位置上的图像必须具有良好的分辨率,以匹配每个分辨率,这意味着它的分辨率至少为960 * 1280,分辨率为480-320 dpi,然后可以通过imageloader类将其设置为imageView,然后需要使用scaleType =“ fitXY”属性添加到您的图片视图,因此它将根据您的图片视图适合该图片

now you are thinking why image stored on location want to be atleast 960*1280 with 480-320 dpi ? 现在您在考虑为什么存储在位置上的图像至少要具有480-320 dpi的960 * 1280?

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) 原因是如果它是低分辨率的图像,那么当您尝试在hdpi或xhdpi上显示时,它们在这些重新分辨率上会失真,这就是为什么希望它会清除所有疑问并为您工作(对我有用)

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/ http://square.github.io/picasso/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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