Differences between scaling images with dpi as opposed to dp
Asked Answered
K

1

0

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:

enter image description here

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

enter image description here

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

enter image description here

^^^ 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.).

Karlykarlyn answered 17/3, 2016 at 15:48 Comment(2)
We need both because different use cases have best results with different solutions. That doesn't mean every app needs both, or that every app needs to use the same method for all images- use what works best for you for that uiHarrier
Ok, so with Plan A in mind, then what really belongs in the drawable default folder? Only the XML drawable resource files, correct?Karlykarlyn
I
0

@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.

enter image description here

Instead of:

enter image description here

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/

Inquiring answered 17/3, 2016 at 18:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.