how to solve same dpi problem with different screen size - android

my phone is galaxy s9 that is 5.8 inch and xxhdpi. And my virtual test phone is nexus 5 that is xxhdpi but the screen size is 4.95 inch. The imageview from the Galaxy S9 appears to be cut off from the Nexus 5. Layout-xxhdpi applies to the same device, with some looking right and some looking fired. How can I solve this?

I would like to recommend you use Vector drawables.
The major advantage of using a vector drawable is image scalability.
It can be scaled without loss of display quality, which means the same
file is resized for different screen densities without loss of image
quality.
Vector drawables allow you to replace multiple png/jpg/jpeg assets with a single vector graphic, defined in XML.
FYI- For responsive Textsize issue, You should use SDP

Related

Problems in supporting multiple resolutions

I am having trouble managing my application layouts in three different resolutions; 720x1280, 1080x1920 and 1440x2560.
In drawable-xhdpi folder is the corresponding images to 720x1280 resolution.
The folder drawable-xxhdpi is the corresponding images to 1080x1920 resolution and in drawable-xxxhdpi to 1440x2560.
I began to adjust the screens in layout folders. The layout-sw360dp was setting screens for 720x1280 and the layout-sw480dp the 1080x1920.
When testing in the emulator 720x1280 all settings worked perfectly.
But to test the emulator 1080x1920, oddly taking this information in layout-sw360dp folder and not the layout-sw480dp.
In the case of adjusting each folder layout-sw360dp and layout-sw480dp, I'm using margin with values ​​in 'dp' and emulator higher values ​​(layout-sw480dp) are being dropped are being used and the values ​​of the layout-sw360dp.
How can I manage three screen sizes correctly?
Well designed Android applications cater for varying screen sizes, the screen size being a function of both resolution and density. Using several layout-sw###dp folders allows you to vary the layout according to the width of the display, e.g. showing fewer elements and controls on a small screen and perhaps more detail on a large one.
The 'sw' in the layout folder name is the 'shortest width' a display must have in device independent pixels (dip). One dip = 1 real pixel on a 160 density screen. So on a 320 density screen, 2 real pixels make up one dip.
Your nexus 5 has 480/160 = 3 real pixels per dip. So with a width resolution of 1080, that is 360dip wide.
Your nexus 4 has 320/160 = 2 real pixels per dip. So with a width resolution of 768, that is 384dip wide.
Neither device is more than 480 dip wide so both use the sw360dp folder.
Both devices are physically very similar in size. The Nexus 5 (5.4inch screen) has more pixels than the Nexus 4 (4.7inch screen) but the pixels are physically smaller. So it is correct that the same layout is used for both. The UI should look the same on both devices, assuming you correctly specify the size and layout of your various UI elements in dip.
As a further example, I have an old tablet (10inch screen) with a resolution of 800x1280 and a low density of 149, hence is 859dip wide. You can comfortably display far more info on a screen that size than on a Nexus 4/5, hence you might consider creating a layout-sw720dp for that.
So you appear to be doing exactly the right thing already by designing different layouts for different screen sizes. Just remember that resolution is not the same thing as screen size. Screen size is a combination of resolution and density.
As for your drawables, you are also already doing the right thing by using drawable-xhdpi, drawable-xxhdpi etc with appropriate resolution images in each one. So for example a small device with an extremely high density would likely use the 1440x2560 images and the sw360dp layout. My low res tablet would use the 720x1280 images, unless you'd put something in drawable-mdpi which is where it would look first.
So firstly you'd create appropriate resolution images in the drawable folders so that they would look as good as possible on different resolution screens. Then create appropriate swxxxdp for your layouts so they take up the appropriate space depending on the physical screen size, i.e. make good use of available screen space on large devices and don't clutter up small ones. It's likely you would want to go further and create -land and -port versions of each as well.
It is worth noting that even if you only have one layout folder and one drawable folder, your application will still work on all devices. Android simply looks for the best choice and if there is only one, it'll use that. Adding in the various folders simply allows you to make your app look as good as possible on a range of devices.
Everything I have discussed here and more is explained in detail at http://developer.android.com/guide/practices/screens_support.html.

Android: Image does not adjust on Galaxy Nexus and Nexus 4 (both xhdpi) but does perfectly on Nexus 7 (also xhdpi)?

I am making an android app that displays an image in the main activity. To adjust the size of this image on different screen size devices I made different drawable folders and added images of corresponding resolutions. In android studio the image is perfectly fitting on Nexus 7 device (1200x1920; xhdpi) but is too big for the GalaxyNexus and Nexus 4 which are also xhdpi devices. Why is this so? Can somebody suggest a way to fix this problem? Thanks in advance !!
<ImageView
android:id="#+id/imageView1"
android:src="#drawable/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
I found the fix finally. This can be taken care of using another folder drawable-large-xhdpi for the tablet.
You are correct that a 2013 Nexus 7 and the Nexus 4 are both XHDPI devices. That means that the system will not perform any scaling on the image that you place into the drawable-xhdpi resource directory on either device, but that doesn't mean the image should just be displayed as-is.
The 4.7" # 768x1280px (384x640dp) N4 is not the same as the 7" # 1200x1920px (600x960dp) N7.
Whilst the density resource qualifier generally works well for things like icons, it alone isn't always enough to provide a responsive layout.
What is the image, and how will it be used? Is it a large background image / full screen image?

Font size issue in Nexus 5 and Samsung s 5

I have values-xxhdpi folder having dimens.xml file, i set the font size 34sp in nexus 5. When I put this on the samsung s5 the font looks very small. Is there any possible way of having the font size look the same (size wise) on both devices?
android:textSize="#dimen/font_size_34sp"
I have find screen size difference
Nexus5 4.9"
S5 5.1"
Provide me generic solution, if possible I want to be able to do this in XML.
You could have a method at run time (onCreate) to get the screen dimensions then based on that re-size the font dynamically.
As different phones have the same DPI but different screen dimensions.
Please also view this

Text scaling properly on different mdpi devices with different resolutions

I've started work to get my games to scale nicely on the higher-res displays like the Xoom and Galaxy Tab 10.1.
I've made use of the ldpi/mdpi/hdpi/xhdpi folder naming convention for my resources which works nicely for layouts and graphics, but not so much for text size scaling. The problem is that an Evo and a Galaxy Tab 10.1 (for example) are both mdpi devices and will map to the same layout file. Yet, I need to scale the text size for some of my TextViews differently for these two devices. For the record, I'm using dp for the text size units.
Any ideas would be much appreciated.
Mike
Consider using sp for text sizes.
Apply different layouts based on screen size (not screen density), as described at http://developer.android.com/guide/practices/screens_support.html.

Android: how to draw an ImageView with the same size regardless of device?

I want to put a toolbar in my application. The toolbar will use ImageViews as application buttons. I would like the ImageViews to be the exact same size regardless device; by "same size" I mean that, when rendered to the screen, if I measure them with a ruler, the dimensions will be the same. I would like this size to be ~10mm (the width of my index finger).
I have been completely unsuccessful in accomplishing this.
I am testing on a MDPI, large screen Acer Iconia Tab and a HDPI medium screen Samsung Galaxy Tab. If I set layout_width="50dip" and layout_height="50dip", the buttons render as ~10mm on the Samsung, and ~8mm on the Acer. If I set the buttons as layout_width="12mm" and layout_height="12mm", they render as 12mm on the Acer and ~9mm on the Galaxy (confusing that 50dip renders bigger on the Galaxy than the Acer, but 12 mm renders smaller on the Galaxy than on the Acer).
If I place a 32pix x 32pix icon in my drawable-mdpi folder (and no equivalent in the drawable-hdpi folder), and set layout_width="wrap_content" and layout_height="wrap_content"; the results are similar to if set to 50dip, the Samsung is about 10mm, the Acer about 8mm. If I add a 48pix x 48pix icon to my drawable-hdpi folder, there is no change; presumably because the Acer still uses the mdpi icon and the Samsung uses the bigger one, but scales it down by 50% because it knows its hdpi (if am confident that this surprising scaling occurs because if I move the 48pix icon to the mdpi folder, and have nothing in the hdpi folder, the icon shows very large on the Samsung).
I am confused and could really use advice. How do I make my button fingertip sized regardless of dpi and screen size?
Ok, I finally figured out what is going on:
The problem is that a image button who's width is specified as 10mm,
shows as about 7mm on my Galaxy tab, and about 9mm on my Iconia Tab.
There are 2 reasons for this rather significant difference:
The Iconia Tab reports its xdpi as ~160, when its actual xdpi
is ~150.
Honeycomb uses a new drawable for its button background, with
significantly smaller margin than the drawable in Froyo.
Issue 1 accounts for about .6mm of the difference, Issue 2 accounts
for the remainder. Issue 2 can be solved by choosing one of the two
backgrounds, packaging it with the application, and specifying it as
the background for the ImageButton. Issue 1 cannot be resolved, but the difference it creates is relatively minor once issue 2 is dealt
with.
You have two basic approaches:
Use supplied resource indentifiers - hdpi/ldpi/etc - and just rely on the OS.
Use xdpi/ydpi in DisplayMetrics class. They are supposed to return the exact physical pixels per inch and scale the image manually with a corresponding scale factor. This, of course, will slow down performance. What is more - I am not sure whether these readings will be correct.
Did you try stuff in the no-dpi resource identifier. Honestly I'm not sure what you would get out of this but it's worth a shot.

Categories

Resources