I'm trying to understand multi-screen support in android. Yes I read the documentation, but still have few questions.
As I understand i need to create drawables for each density, but what to do with text size?
I want to set title on my activity which will fit any screen (need to big big enough and don't warp the text)
I test in on my Nexus7 (large screen) and it looks good with android:textSize="100dp"'
When i launch it on emulator with 'normal screen' size i get very big text.
So is it right solution to make layouts for each screen size?
'layout'
'layout-large'
'layout-small'
....
and just make android:textSize="70dp" for normal screen and android:textSize="50dp" for small screen?
And another one question how to test all this in more efficient way?
I need to create emulators with? Where to get parameters with which create emulators to get this results?
XLarge screen
ldpi
mdpi
tvdpi
hdpi
xhdpi
Large screen
ldpi
mdpi
tvdpi
hdpi
xhdpi
Medium screen
ldpi
mdpi
tvdpi
hdpi
xhdpi
Small screen
ldpi
mdpi
tvdpi
hdpi
xhdpi
For text size you should use sp units. Docs say:
Scale-independent Pixels - This is like the dp unit, but it is also
scaled by the user's font size preference. It is recommend you use
this unit when specifying font sizes, so they will be adjusted for
both the screen density and the user's preference.
As I understand i need to create drawables for each density, but what to do with text size?
As WebnetMobile indicates, you start by using sp, as this takes the user's choice of font scale into account. However, you may need more than that.
So is it right solution to make layouts for each screen size?
I would recommend using dimension resources, with different definitions for the text size dimension as needed for your different scenarios.
Where possible, though, design your UI to be more flexible about font sizes. Again, if you use sp, the user can change the size of the text on Android 4.0+, to make it bigger or smaller, to help them read the text on their device. Hence, you cannot assume that you are in complete control over the size of the font, and therefore need to design accordingly. This is not significantly different than designing a Web site that takes into account users' adjustments to font size in their browser.
And another one question how to test all this in more efficient way? I need to create emulators with?
You will need emulators or devices for whatever scenarios concern you.
Where to get parameters with which create emulators to get this results?
On the (now-current) R21 versions of the tools, you set the screen size and density in the Device Definitions tab of the AVD Manager, then create AVDs based upon those definitions as needed.
Inorder to test in different screens and density you can create emulators with different combinations. When we create the emulator device we can set the Density (Abstracted LCD density under hardware).
ldpi - 120
mdpi - 160
hdpi - 240
xhdpi - 320
You can set the screen size also while start the emulator
Related
I’m new to Android programming and I’m stuck with a very specific problem. I want my application to run on multiple screen sizes and densities.
I have several real devices with different screen resolutions (Samsung Galaxy S7 Edge [xxxhdpi], Samsung Galaxy A5(6) [xxhdpi], Samsung Galaxy Note 10.1 tablet [xhdpi].
I made one background and scaled it down for every generalized density. I saved the files as “background.png” in separate folders like suggested in Supporting Multiple Screens.
After testing the APK on the devices, everything worked fine except the background on the S7. It will always load the next lower resolution bitmap (xxhdpi instead of xxxhdpi). I looked countless threads how to fix this problem but nothing worked so far.
The resolutions of my bitmaps are:
drawable-mdpi //320x480
drawable-hdpi //480x800
drawable-xhdpi //720x1280
drawable-xxhdpi //1080X1920
drawable-xxxhdpi //1440X2560
I hope that someone can help me on this one. I’m really losing my mind.
This is a little complex but I'll try to keep it simple. The android system chooses the right resources based on a lot of factors (which you can see when you create a new resource file under the "Available qualifiers" list) which you can group to create a resource shared by different configurations or use only one of them to specify one particular configuration. But you cannot control witch resource the device will use for the most part (there are some you can specify yourself ex: night mode). Your S7 probably uses the wrong resource because probably one of the settings for the display resolution is set at a lower setting (ex: battery saving modes lower resolution, gaming mode.. etc, accessibility settings). And if you want a tablet to use a different drawable then a phone then you should use the "smallest screen width" qualifier since you can specify different screen sizes in Dip(ex: sw320dp is a normal phone, sw440dp is a big pixel phone, sw720dp is a medium tablet and sw1048dp is a bigger tablet). Read more here
I'm also facing like this. My app only works on high resolution mobile only. Then I found that error. I placed my drawable on drawable-hdpi only . For every assets we have to place default drawable in drawable folder
put default drawable in that folder.
drawable
For handling images on the s7 device we can give height and width to the image view. Set the values for height and width from the dimens file. For handling s7 UI need to add the dimens-sw411 file and specify the height and width in that.
At present the resolution of Android wear devices is:
280x280 or
320x320
Does anyone know if you should have graphics for both the screen sizes and place them under the hdpi and xhdpi folders?
Also is there a way to auto scale down your images from 320x320 so that they work on a 280x280 device?
Thanks!
hdpi should be all that you need, all watches are a hdpi density
I would create background images at 320x320 and android will automatically scale them down to 280x280 if needed.
You will need to watch out for round devices, as they are 320x320 but the corners will be cut off
I'm have tired to support all android , but I want to ask about supporting all screen size on android
I have 4 layout folders :
layout
layout-ldpi 2.7 inch = 240*320
layout-mdpi 3.2 = 320*480
layout-hdpi 3.7 = 480*800
layout-xhdpi 800*1280
layout-xxhdpi 5 inch 1080*1920
Is this setting in each layout support all devices or maybe I have missed some thing ?
Note : I have reviewed android site Android Developers many time .
I'm not sure what you want to achieve. You should split your resoures in two groups. One with density (folder called drawable) which contains images in different sizes for different display resolutions. The second one with layout (called layout) is for supporting different UI layout of each screen. Typically for tablet or mobile phones. So you should have forlder
drawable-ldpi, mdpi, etc. - here will be your png files
layout-"default",sw360, sw600, sw720 ("large" mobile, small 7" tablet, large 10" tablet). If your are targeting below 3.2, you can't you sw (smallest-width) but use older small, medium, large, xlarge screen size. - here will be your *.xml layout files
Don't mix up layout and density resource qualifiers together. See more here
I am new to Android Development. I have recently developed an app that supports Screen sizes of 3" to 4"! The problem is that When I run my app on my HTC Wildfire S (3.2") it works find the screen visuals are fine to see and it gives best resolution.
But when I run the same app on my Samsung Galaxy Y S5360 (3") a small portion of the screen vanishes at the spot I mean the screen visuals are not so much visible to see and gives bad visuals of screen.
Why it is so when I have set the screen size as ranging from 3" to 4". I am using Relative Layout and in the Eclipse IDE the Screen is showing so well also.
HERE is the Eclipse IDE image
HERE is my Samsung Galaxy Y S5360 Image: sorry for poor image.
YOU can see the problem of text at the bottom of cell phone image how can i fix this? please help thanks in advance!
First- never trust the eclipse plugin. Its buggy, and its an estimation anyway. You can use it to see if you're roughly right, but never expect it to look like that ont he actual device, much less on all devices.
As for your problem- the screen on your device is too small for your layout. You either need to cut out whitespace or shrink something. If you can find out the exact resolution of this device you could make a special layout for devices of that resolution.
This is a standard problem in android UI design- you're developing for a lot of screen, some of which are very small. If you want it to work on everything, you have to be very careful with the amount of content and empty space on each screen and test against a variety of resolutions and physical sizes.
A good way to get around this is to size everything in dp. 1dp=1/160th of an inch. Then you know how big a screen you'll show on.
My 2 suggestions are as below
1.Can you try using scroll view for your content
2. apply full screen to your app & change the current layout of the app(if in case of linear layout)
At the moment I have just targeted my UI graphics for the hdpi resolutions for android and this works flawlessly, the graphics are designed with 3 resolutions in mind with only the background image being altered really. Problem is the plan was to use the same images for hdpi (480x800 and 480x854) and as well as mdpi (320x480). But when I test it for mdpi with the images in both the -hdpi and copied into -mdpi it doesn't scale them down, do I have to resize all the images and have them duplicated for the mdpi screens?
Sorry if this is not very eloquent it is the first time I have done any UI design for android and still don't understand it properly.
Android should correctly use the right image when you use R.drawable and your images are in drawable-hdpi, drawable-mdpi etc. Since that is what I think you've described as what you've done, it hints that maybe you've hardcoded a size? Are you using ImageView and set a size for them? If so, did you do it in Java code or in XML? If in Java code the values would be in pixels, so 50px on mdpi screens will look larger than on hdpi screens. If you used XML did you again set a size with px? If so, you should use dp.