缩放与DPI的图像,而不是DP之间的区别 [英] Differences between scaling images with dpi as opposed to dp

查看:293
本文介绍了缩放与DPI的图像,而不是DP之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有的DPI可绘制目录(是xxhdpi和xxxhdpi甚至是必要的?)组成的九宫格位图,在绘制目录中的绘制资源文件检索所有的缩放位图,我设置的背景与绘制资源文件按钮......现在,我的问题是尺寸(小,正常,等)而言,在我试图手动更改按钮作为的DP,我还创建了缩放布局目录如下:

下面是我的xhdpi位图:

在这里输入的形象描述

...但现在看来,这样的的Nexus 7的虚拟仿真器(7.0,1200X1920:xhdpi)在布局大型目录:

在这里输入的形象描述

...当我手动更改DP大小按钮中的一个的200:

在这里输入的形象描述

^^^怎么办我的目录的方式看? ......又为何按钮出现这样呢? ^^^

所有的说,我只是不明白为什么我们需要基于密度绘制资源目录(MDPI,华电国际,xhdpi,等)的以及布局资源目录,当我们可以只是简单地修改图像的DP在每一个独特的布局对于屏幕的尺寸(小,正常,等等)。


解决方案

@ dpark14我基本上已经回答你在你的帖子从昨天在这里提出这样的问题:<一href=\"http://stackoverflow.com/questions/36046531/is-modifying-the-dp-size-as-opposed-to-pixels-recommended-for-various-screen-siz/36050317\">Is修改DP的大小,而不是推荐的各种屏幕尺寸的像素?


  1. 也许你应该修改你的最后一个问题,以包括code和图像上面,因此它可能得到巩固。

  2. 正如我在答复中指出(及其他意见一说):


  

这完全取决于你,如果你想改变的ImageButton的布局宽度和高度(DP)。当然是有什么不妥的设置或者的ImageButton为此事的任何UI元素的宽度和高度,在不同的屏幕上每个独特的布局资源文件。有没有特别code你想获取反馈?


现在,您已经包括了一些照片,我可以看到一些你所拥有的。

您真的应该看看这个:
Android的工作室绘制文件夹

和这将有利于你再通过Android文档阅读:
http://developer.android.com/guide/practices/screens_support.html

要总结一些总体思路:
你并不需要的默认的绘制文件夹,但你应该具备以下条件:


  • 绘制-MDPI(中)〜160dpi

  • 绘制,华电国际(高)〜240dpi

  • 绘制-xhdpi(超高)〜320dpi

  • 绘制-xxhdpi(超特高)〜480dpi

  • 绘制-xxxhdpi(超超特高)〜640dpi

由于Android文档中上面的链接说:


  

您的应用程序实现密度独立时,美元不同密度的屏幕上显示当p $ pserves物理尺寸(但从用户的角度)的用户界面元素。


在这里输入的形象描述

而不是:

在这里输入的形象描述

如果由于某种原因(因为它看起来像您遇到的问题),你已经取得了密度独立,但你的形象不吻合,这时候你就可以开始改变W / H介入和RES /布局

同时从previous答案:


  

至于你提到的:你可以创建基于最低标准的各种设备如不同的RES /梦诗目录w800dp / dimens.xml,然后创建该特定dimens.xml例如元素与您的图像对应值-W411 / dimens.xml的宽度和高度,没有装修好,当您测试您的应用程序。


作为第一步,也许你应该尝试一下。是的,这需要时间,但第一次尝试从您的应用程序的独立测试分开。只需添加一个图像(也许您有问题的)。见时将其加载到模拟器不同的Nexus设备会发生什么。是否图像实现密度独立,即preserves跨设备的物理尺寸?如果确实如此,而且也涉及到一个特定的设备的局限,其W / H的问题,正如我在previous回答说和的现在在这里的,创建一个梦诗目录(内一个值-...目录)专门为有问题的设备,并更改该特定图像或视图中的layout_width / layout_height。

有关更多特定设备上宽/高: https://design.google.com/devices/

I have all of the dpi drawable directories (are xxhdpi and xxxhdpi even necessary?) consisting of nine-patch bitmaps, the drawable resource file in the drawable directory that retrieves all of the scaled bitmaps, and I set the backgrounds of the Buttons with the drawable resource file... Now, my problem is that I also created "scaled" layout directories in terms of size (small, normal, and etc.), in which I tried to manually change the dp of the buttons as follows:

Here's my xhdpi bitmap:

... But it appears like this on the Nexus 7 virtual emulator (7.0", 1200X1920: xhdpi) in the layout-large directory:

... And when I manually change the dp size to 200 of one of the buttons:

^^^ How do my directories look by the way? ... And why does the button appear like that? ^^^

All of that said, I just don't understand why we need density-based drawable directories (mdpi, hdpi, xhdpi, and etc.) as well as layout resource directories, when we could just simply modify the dp of images in each unique layout regarding the screen's size (small, normal, and etc.).

解决方案

@dpark14 I basically already answered the question you asked in a your post from yesterday here: Is modifying the dp size as opposed to pixels recommended for various screen sizes?

  1. Perhaps you should have edited your last question to include the code and images above so it could be consolidated.
  2. As I said in my answer (and one of the other comments said):

It is entirely up to you if you want to change the layout width and height (in dp) of an imageButton. There is certainly nothing wrong with setting width and height of an imageButton or any UI element for that matter, in each unique layout resource file for various screens. Did you have specific code you wanted to get feedback about?

Now that you have included some images I can see some of what you have.

You should really take a look at this: Android Studio drawable folders

And it would benefit you to read through the Android documentation again: http://developer.android.com/guide/practices/screens_support.html

To summarize a few general ideas: You don't need a default drawable folder, but you should have the following:

  • drawable-mdpi (medium) ~160dpi
  • drawable-hdpi (high) ~240dpi
  • drawable-xhdpi (extra-high) ~320dpi
  • drawable-xxhdpi (extra-extra-high) ~480dpi
  • drawable-xxxhdpi (extra-extra-extra-high) ~640dpi

As the Android documentation says in the link above:

Your application achieves "density independence" when it preserves the physical size (from the user's point of view) of user interface elements when displayed on screens with different densities.

Instead of:

If, for some reason (as it looks like you're having issues with) you've achieved density independence, but your image doesn't fit well, that's when you can start to step in with changes to w/h and res/layout

Also from my previous answer:

As you alluded to: you could create different res/dimens directories for various devices based on "minimums" e.g. w800dp/dimens.xml and then create elements in that specific dimens.xml e.g. values-w411/dimens.xml for width and height that correspond with your images that aren't fitting well when you test your app.

As a first step, perhaps you should try it out. Yes, this takes time, but try a stand-alone test separate from your app first. Just add one image (perhaps the one you are having issues with). See what happens when you load it into different Nexus devices in the emulator. Does the image achieve "density independence" i.e. preserves the physical size across devices? If it does, and there's an issue with its w/h in relation to the confines of a specific device, as I said in my previous answer and now here, create a dimens directory (within a values-... directory) specifically for the problem device and change the layout_width/layout_height for that specific image or view.

For more on specific device w/h: https://design.google.com/devices/

这篇关于缩放与DPI的图像,而不是DP之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆