I am developing for android and my code runs perfect on nexus or any 3.7 inch device.
If I run it on tablet (7 or 10.1 inch) then the fonts and buttons are very small and the spacing is way too big.
If I run it on 2.7 QVGA then the buttons are too big and overlap.
I am using dp and sp all over the layout so I am surprised it didn't adjust according to different screen size/density.
Does that mean that I have to wrte the same XML layout in 3 layout folders (large, medium and small) and put my drawable in 3 different density folders?
Or am I amissing something here. Yes I read the "Supporting multiple screen" document and it just loses me with the details (but I did follow the tips of using dp and sp). I am looking for more of a summary/general approach answer.
dp and sp adjusts according to screen density. Therefore, a screen with 500 dpi and 4000 dpi but with the same SCREEN DIMENTIONS will looks the same.
If they have different screen sizes, it won't fit as you want. If you want to support multiple screen sizes, you'd have to use weights or percentages.
The key is that dp = device independent pixel and it only adjusts according to density, not screen size.
In the most cases if you don't make a tablet app, you don't need to make more than one XML layout for different densities/sizes. All you must do is define dimensions with DP and SP as you said.
But is necessary to provide different images in the drawable folder to show one or other in function on screen size/density.
If you put all images in drawable folder (without specify hdi,ldi or mdi) Android will try to adjust the images but not always works fine.
Hope it helps.
Related
I want to display some values on screen such that they occupy roughly the same percentage of screen area irrespective of display size or pixel density. How do I do that?
When I use dp or sp I get the following results for the same font size a tablet and on a phone.
One a 1280x768 4.7 inch phone:
On a 1280x800 10 inch tablet:
Try using SDP library for mentioning dimens in your XML file.
After that there will be no need to prepare multiple layout files.
Please check this library,
that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size. It can help Android developers with supporting multiple screens.
You've to create different layout folder, for instance for devices like 7" tablet (600x1024 mdpi), you'll have to create the folder res/layout-sw600dp/ and in there put the layout that you want to display on screens that has this screen-size and change for instance the TextView text size, position on the screen, etc...
I recommend you to read the Support different screen sizes documentation, there's well explained how to do that.
Also you have other way to do that, it's better the first one, but I personally used this library and it worked well for me because the layout were not that big.
Test this SDP - a scalable size unit library, then you do now have to create different layouts or yes deppends of your likes
app screen on galaxy s4 it skip right and bottom part because of small size mobile
I am having problem in Design different screen size.
how should all 5 categories will support most of the mobile screen?
my Android App Design Normal screen works on 5 inch mobile screen where as for 4 inch screen it skip below content.
for example it work nice on samsang galaxy s4 (5 inch) also on nexus 4.
but as shown in image when i see on nexus S(4 inch screen) it skip some bottom and right part .it cannot hold full layout mostly top and left part it display.
how to design normal screen which support these screen size changes?
is it compulsory to use wrap_content or Match_parent or fill_parent only to get rid of it.
for that also i am confused of specifying image size for different screen size in drawable.
also is normal screen be of different density such as hdpi,mdpi,ldpi etc.
how to solve this issue is it sufficient to use dp and sp?
and last one, in Android Studio we design 5 types of layout.for example activity_channel_list.xml(small). etc( for normal,large,xLarge).what last just activity_channel_list.xml represent.is it like if not any layout is selected.this will be selected by default.
Thanks in advance.
If you want to design layouts for different screens then make folders accordingly link
layout-mdpi
layout-hdpi
layout-xhdpi
layout-xxhdpi
If you don't want create different layout for different screens then simply use dimension file and create different dimens in that like
values-hdpi (dimen)
values-xhdpi (dimen)
values-xxhdpi (dimen)
and the difference between dp and sp is, we use dp for give dimensions to the image, and for size purpose and sp is use for define text size
the screen size id efferent and you cant make a layout for every one you need to try categorize the screen with layout selector
if you use sp for text the text size will change when user change the android font size and it is better to use dp for text
and last Question is like first one you need to categorize layout for size and density normaly
How should all 5 categories will support most of the mobile screen?
Take care if these following aspects while designing layouts:
1.Always design layouts inside scrollview, so that for smaller screens user will be able to view complete layout by scrolling
2.Use sp for text Sizes
3.Use dip(density independent pixels) for all widget sizes, usage of dip makes the size of widget according to mobile profile(like 240*320 may use ldpi so according widget size will change)
4.All the icons you are using you need to generate for all profiles(ldpi,hdpi,xxhdpi,xhdpi) and store in drawable-xxxx folder
If you dont want to generate images for all profiles you can use font icons (like font awesome,iconmoon)
font icons appear according to screen sizes.
5.Last but not least, avoid using hardcoded margins between widgets use attributes like gravity,center_in_parent etc.. so that screen looks uniform in all devices.
trying to get my head around screen sizes so my app looks the same on different devices.
I have two devices a galaxy s3 and a galaxy tab 8. both have the same resolution screen 720 x 1280 but the s3 is 4.7 inches while the tab is 8 inches
When I do a linear layout I set padding to 130 at the top so that the first textview is 130 pixels from the top so the image on the background is not obscured.
This is fine on the s3 but when I load it on the tab the padding needs changing to 190 pixels for it to look the same.
I cant get my head round if the height of the screen resolution is the same (1280) on both devices why do i need larger padding on the screen
is there a way of working out how to make the textview appear on the same location on both devices
Any help appreciated
Mark
Yes there is a way.
First off all you should use DP or SP unit instead of PX. The DP unit have in consideration the size of the screen and the screen resolution. You can see more in here:
What is the difference between "px", "dp", "dip" and "sp" on Android?
Also you can create a folder in res and add different sizes for different devices.
Example:
You already have the folder 'values' with the file 'dimens.xml' in there you can add margins and sizes variables.
If you create the folder 'values-large' and copie the file 'dimens.xml', you can change the sizes of the variables and maintain the name.
In devices 'large' it will load different values from the rest of the devices.
You can see all documentation in here: http://developer.android.com/guide/practices/screens_support.html
Hope it helps you.
You need to add 2 different layouts for 2 different screen sizes. In fact you can provide multiple screen support limited only by your considerations. You can customize layout according to the screen sizes. Here is the official documentation to help you get going.
First of all, you need to use dp instead of px to do these kind of stuff. The reason the result is wrong is that the number of dots per inch on the s3 is much higher than that of the galaxy tab 8. You should really read this link to understand more.
[http://www.captechconsulting.com/blog/steven-byle/understanding-density-independence-android][1]
Assume that I am defining a button or text view width as 100 dip and height as 30 dip in XML file. As for As I know, Android itself take care of that button or text view appearance proportionate or same among ldpi, mdpi or hdpi devices as I defined dimension in dip. This is one of the recommendations, if you want to provide multi screen support. My Question is does dip is only useful in handling ldpi,mdpi or hdpi devices with same width and height means all 320X480 or all 400X840 like that or is it also support across multi screen dimensions means If I define a button with 100X30 dip for 320X480 device, after adding all screen support true in manifest file, android system it self will recalculate the widget size to some 200X60 dip to 700X1024 device.
If dip does n't work across multiple screen sizes(if device physical sizes are different) then I need to write sepearte layout file for each devices where I can't define my complex layouts with Linear Layouts with some weights, correct me if I wrong. Are there any alternatives, suggest me. Thanks In Advance.
dip is "density-independent", so these measure units are tied to density and not the screen size. For example, there are 10" tablets that are still mdpi, and of course layouts that look well on small mdpi phones will look terrible on those devices. The workaround here is to use dimension values and override them for such cases. Now, instead of using, for example, 10dip inside your XML, you will be using #dimen/dip_10, which will have different values in values/mdpi and values/xlarge-mdpi. Hope this helps.
can I change layout dpi that use my application on device?
(on developed application that works fine but on small screen size devices everything looks big )
You'll want to supply resources for all the screen size buckets:
/drawable/ (default images)
/drawable-ldpi/ (small dpi screens)
/drawable-mdpi/ (medium dpi screens)
/drawable-hldpi/ (large dpi screens)
/drawable-xhdpi/ (xtra large dpi screens)
See here for help: http://developer.android.com/guide/practices/screens_support.html
and here for a list of devices using which DPI bucket: http://blog.blundell-apps.com/list-of-android-devices-with-pixel-density-buckets/
small screen size devices everything looks big .
Read this Supporting Different Device
Its an layout issue ,Try to use relative layout and linear layout for placing the objects in xml.And for images use .png extension and use nine patch images ,so that it fits in all screen,this will support most of the screens
You need make images for all DPI screen so that it is supported by all types of devices.
Android automatically sets these images for your application according to your device DPI.
Please be sure of all of your resources and see link. It will help you more.