Multiple XHDPI Device Resolution - android

I need to handle multiple XHDPI devices resolution. As far as i came to know, there are following Dimensions that are falling in XHDPI Range :
1184x768
1280x720
1280x800
1224x720
as they all belong to same Dimension, how to differentiate the Resources (drawables) it should load according to screen dimension?
or
If I use a single XHDPI layout and place their drawable in xhdpi folder is it sufficient or will this thing disturb the UI
Thank you

XHDPI is a single bucket
Short Answer:
A single layout for XHDPI will suffice with their resources placed in
the proper (xhdpi) drawables folder.
Long Answer:
Android Devices vary so much, so android decides that these set of screen resolutions fall under one bucket i.e. treated as one device since the variation among themselves is relatively lesser compared to the whole range. Android does runtime image manipulation to adjust your resources a little so that they function as expected.
Bonus:
To have finer control on images, look at the Scale attribute.

you can read more here
http://developer.android.com/guide/practices/screens_support.html
basically if you want...you can create folders with the following names:
layout-sw520dp-port //Galaxy Note at v4.0.3
layout-sw520dp-land layout-sw600dp-port // Nexus 7
layout-sw600dp-land layout-sw700dp-port
layout-sw700dp-land
etc. etc

Related

app's UI is not proper in a 220 dpi screen

hi I'm new in android developing and it's my first app.
I have made these folders in address : app\src\main\res for supporting multiple phone and tablet screens and put proper dimens.xml files in them.
values-ldpi
values-mdpi
values-hdpi
values-xhdpi
values-xxhdpi
values-xxxhdpi
values-sw600dp
values-sw768dp
values-sw800dp
first of all, are they complete or am I missing some screen sizes?
second, I've tested the app on several devices and it's working fine and has proper user interface in all phones but on the Galaxy Grand Prime which has a 5 inch 540 x 960 pixels display that means 220 dpi. this phone using hdpi dimens but UI is a bit messy.
The following pictures may make my point better :
Proper UI , as it is shown in other devices
VS
UI in galaxy grand prime 220 dpi display
as UI is completely OK in other devices, I thought I should make a specific dimens.xml file for that kind of dpi, so I made values-sw220dp. but after that other phones used this dimens instead of hdpi dimens and problem got worse because UI was fine in the galaxy phone and was not proper in other hdpi displays. and now I don't know what should I do.
can anyone help me in this issue?
at last sorry because of flaws in my english , as you can guess I'm not a native.
are they complete or i'm missing some screen sizes?
If you read the guides which I mentioned at the end of my answer you will find that there are very many possibilities of defining resources folders. I think nobody will want to implement all of them.
Usually you look at your app and then decide on maybe three or four screen sizes you want to support. I think "sw220dp" is important, if only to show a message that your app needs more space :-).
So there could well be three to five layout folders (sw220dp, sw320dp, maybe sw480dp, sw600dp, maybe sw820dp). If you need orientation-dependent layouts, then the number will be twice that much. (Why ? That's explained very well in the guides linked below)
You already know that there are different types of resources. Some of them do not depend on the screen resolution (e.g. layout files), some do (drawable resources).
So first of all you decide which screen sizes you want to support. Let's say they are "phone", "tablet" and "220dp". You create three layout files by the same name "my_activity.xml" and put them in three folders
for the really small window: res/layout-sw220dp
for the mobile phone: res/layout-sw320dp
for the tablet: res/layout-sw600dp
By the way, "sw" stands for smallest width which is the minimum length of the screen, no matter what the orientation is currently.
Now let's assume you have created three different layout files and all of them contain an ImageView like this:
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="#drawable/my_picture" />
This is where the screen resolution comes into play: 24dp is a size value in "density-independent pixels". It will be resolved depending on the screen resolution of the device. So you need different versions of my_picture.png, and for this you need different folders for drawables. They are named after the different categories for screen resolution so the runtime knows which png file to pick:
res/drawable/ldpi (although I read somewhere you can skip that because the pictures will be scaled down from hdpi nicely)
res/drawable (here go the resources for res/drawable-mdpi as well as every drawable resource for which resolution does not matter, e.g. drawables defined via xml files)
res/drawable-hdpi
res/drawable-xhdpi
res/drawable-xxhdpi
res/drawable-xxxhdpi
Helpful links:
Providing Resources
Supporting Multiple Screens

Differences between scaling images with dpi as opposed to dp

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?
Perhaps you should have edited your last question to include the code and images above so it could be consolidated.
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/

Android different screen size and different densities [duplicate]

This question already has answers here:
Android screen size HDPI, LDPI, MDPI [duplicate]
(4 answers)
Closed 9 years ago.
I have to manage different screen sizes and different densities in my Android app.
I am not getting directory structure properly.
What I understand so far is there are four types of screen sizes:
small
normal
large
xlarge
and different densities as well:
ldpi
mdpi
hdpi
xhdpi
Now each device size (small , normal , large and xlarge) shall map against each density. Because every size can have different density, right?
If yes, then we can say small screen have all the density i.e ( ldpi , mdpi , hdpi , xhdpi)
same for normal, large and xlarge.
The point is how I'll manage them in my drawable directories.
Will there be four folders for small screen size with different size (drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi)?
And same for other screen sizes as well.
If not then how I'll manage all the image in ( drawable-ldpi , drawable-mdpi , drawable-hdpi , drawable-xhdpi) folder because different screen size I'll have different size of images. Then how can a small device with different density and large device with a different size be manageable in same density folder.
Please don't give me reference of any Android document as I read all that stuff.
If any one can't get my point, then please let me know. I'm very confused.
When I have started development in Android, I was confused about same issue.But now I have figured it out and I'm doing pretty well.
Anyways, You are absolutely right.you can provide different images by 4 folders for each.i.e.: drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi
But it is just waste of your time.because you don't need to worry this much about it.Android can scale up/scale down according to the device configuration.so just provide extra images for those devices only if you don't get desired outputs for them.
As far as I know, supporting multiple devices, you have to consider few general criteria in your mind.
Density qualifiers: ldpi,mdpi,hdpi,xhdpi,etc are generally used when you want to provide different resolution images.
Size qualifiers + Orientation qualifiers: small,normal,large,xlarge,sw600dp,normal-land,normal-port,etc are generally used when you want to provide different layout designs.
i.e.: single pane layout,multi-pane layout,different elements in layouts according to different screen sizes.
For reference: Download the example app from here and try to understand how it is being supported for multiple screens.
I hope it will be helpful !!
Here are official docs for you to read about the subject: Supporting Multiple Screens then Supporting Different Screen Sizes
Put your all image in all different folder that is drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi and drawable-xxhdpi. android will take care of it.
What I always do is just put all my images in one folder (usually xhdpi). The Android system will scale them for you so you don't have to worry about what to put in what folder.
Heres what Android says about this:
Provide different bitmap drawables for different screen densities
By
default, Android scales your bitmap drawables (.png, .jpg, and .gif
files) and Nine-Patch drawables (.9.png files) so that they render at
the appropriate physical size on each device. For example, if your
application provides bitmap drawables only for the baseline, medium
screen density (mdpi), then the system scales them up when on a
high-density screen, and scales them down when on a low-density
screen. This scaling can cause artifacts in the bitmaps. To ensure
your bitmaps look their best, you should include alternative versions
at different resolutions for different screen densities. The
configuration qualifiers you can use for density-specific resources
are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high).
For example, bitmaps for high-density screens should go in
drawable-hdpi/.
You can find the documentation here:
https://developer.android.com/guide/practices/screens_support.html
Hope this helps

Adjust view sizes in android for custom devices

I have 3 custom made android devices.
First one has a 5 inch screen with 1280x800 res
Second has a 5 inch screen with 800x480 res
Third has 7 inch screen with 800x480 res
I tried giving sizes with dp, px and inches but it seems they cant support those screens properly with the same value (even inches seems to be not exact inches but translation to px eventually).
How can i use same code to properly adjust view sizes relatively to the screen size?
Well, as first, the correct measure unit to use is: dp for controls and sp for fonts.
These are normally for margin, paddings, widths, heights, and other attributes.
Also xml drawables can take advantage of pixel independency
Define your dimensions in a res/value/dimens.xml file (this is a PROPOSED standard name, you can call it whatever you like best), in order to have them referrable from all your code, instead of being hardcoded and often repeated in many files.
Then you must know that you should provide your graphics AT LEAST in mdpi resolution (160 dpi), which will be scaled up or down to match other resolutions.
Notice that I said at least.
For every resolution you are supporting, you should add a folder in your res path containing the graphics at the corresponding density for that resolution.
this means that you will have, let's say 3 resolutions mdpi, hdpi and xhdpi (today's favourites, excluding tablets - these ones deserve some folders on their own):
The graphics is going into:
res/drawable-mdpi
res/drawable-hdpi
res/drawable-xhdpi
Just put your graphics (with the same names) with (respectively) a dpi density of 160, 240, 320 in those directories.
Now your graphics is resolution compliant.
Now, I don't realize what the problem really is.
I mean, is it the background not fitting well? then the solution is to use a tiling or an "abstract enough" stretchable picture.Or you could use 9 patches, as well
If the problem is how the fonts and other objects interact with each other, you should always reference to an mdpi device (even emulated, if you don't own a physical one). When things scale well on a mdpi device, they are supposed to scale well on every device.
For tablets in particular, you are supposed to provide specific folders for values (where you put your dimens.xml file, containing the dimensions).
These folders normally have names like values-sw600dp or values-sw720dp-land. The suffix land indicates landscape mode, the particle sw###dp indicates the minimum dimension (width or height), so, I guess that in you case you could prepare some folders called values-sw480dp and values-sw480dp-land and there you would put your dimens.xml file, with the special dimensions for that particular device.
I guess that providing only the non-land folder would be enough.

Delveloping for Android high res screens, but supporting low res screens

I've been developing Android games for the lower res screens (320x480) and then letting Android handle the density adjustments so the games work on high res screens. It allows me to keep the size of my APK files small and I don't have to create multiple versions of every image in my games. It actually works fine, the games still look nice on higher res screens.
However, my question is, is it possible to do the same thing, only backwards? Can I develop for high res screens (800x480) and then somehow let android handle the density reductions automatically?
Yes.
In your xml layouts, use dip values for sizes.
Example:
100dip =
75 # 120dpi
100 # 160dpi
150 # 240dpi
if you need a higher res resource for certain drawables, use the...
drawable-hdpi
drawable-mdpi
drawable-ldpi
The app will use the drawable from the correct resource folder depending on the screen's density.
Try not to use absolute widths and heights on certain elements if you can use FILL_PARENT or WRAP_CONTENT.
Here's some good tips:
http://developer.android.com/guide/practices/screens_support.html
Yes, and it works the same. You put your resources in the appropriate directory and the system will downscale them accordingly.

Categories

Resources