简体   繁体   English

在Android应用中显示图片-分辨率?

[英]Showing pictures in Android app - Resolution?

I've a Photo gallery in my app. 我的应用程序中有一个图片库。 The set of pictures are stored in the drawable folder. 图片集存储在drawable文件夹中。 I'm making use of ViewPager when the user swipes through the images.. What is the width and height in pixels and dps for xhdpi, hdpi, mdpi?? 当用户在图像中滑动时,我正在使用ViewPager。xhdpi,hdpi,mdpi的宽度和高度以像素和dps为单位?

I know that the Android documentation says px = dp*dpi/160.. but I'm still confused about what should be the pictures download pixels so that it fits in all screen sizes?? 我知道Android文档说px = dp * dpi / 160 ..但我仍然困惑图片应该下载什么像素,以使其适合所有屏幕尺寸?

There isn't one magic size that guarantees that it fits all screens perfectly. 没有一种神奇的尺寸可以保证它完全适合所有屏幕。 There are more than one screen size that fall under each density. 每个密度下都有一个以上的屏幕尺寸。

You should look at making your layout scale well on as many devices as possible. 您应该考虑使布局在尽可能多的设备上很好地缩放。 In your case it sounds like you shouldn't be focusing on an a specific pixel size, but rather how to display correctly on the common screens and gracefully display on less common ones. 在您的情况下,听起来您不应该专注于特定的像素大小,而是如何在常见的屏幕上正确显示以及在不太常见的屏幕上优雅地显示。 That being said I would do the following: 话虽这么说,我会做以下事情:

I'd look at the dashboard here . 我在这里看仪表板。 I'd make layouts targeting first targeting hdpi with a normal screen size(50.1% of the market) followed by xhdpi(25.1%) with a normal screen size, followed by mdpi(11%) normal screen size. 我将首先针对具有正常屏幕尺寸(市场份额的50.1%)的hdpi进行布局,然后针对具有正常屏幕尺寸的xhdpi(25.1%),然后是具有正常屏幕尺寸的mdpi(11%)。 Check table 3 on this page for common screen sizes for those values. 检查表3本上常见的屏幕尺寸为这些值。 Since you will be most likely using an image view make sure to check out the scale type attribute to help handle when the image view isn't at 由于您最有可能使用图像视图,因此请务必签出比例类型属性以帮助处理图像视图不在

As a side note(maybe useful later)if you are having difficulties translating sizes between densities and raw pixel values use this calculator. 附带说明(稍后可能有用),如果您在转换密度和原始像素值之间的尺寸时遇到困难,请使用计算器。

Use following function which give you height and width of current display 使用以下功能,可显示当前显示的高度宽度

DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
deviceHeightPix = displaymetrics.heightPixels;
deviceWidthPix = displaymetrics.widthPixels;

based on this, you can pass data on server to fetch relative images. 基于此,您可以在服务器上传递数据以获取相关图像。

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

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