In Android is it ok do set the width of a linear layout to 320dp? Can it be to big for some small screens?
On the internet people say that 320dp is the smallest android screen, but I just want to ask if someone tested this. Thanks
This question is related to android dp size for LinearLayout but nobody answered the question so I wanted to try to ask the question in a different way
You can use multi layout files as docs for small and large screens.
We have 2 positions (landscape and portrait) and 2 sizes (normal and large) of screen. So, there are 4 types of layout.
res/
layout/ # default (portrait)
main.xml
layout-land/ # landscape
main.xml
layout-large/ # large (portrait)
main.xml
layout-large-land/ # large landscape
main.xml
You have to create layout file with same name in them.
Instead of using fixed size you should try match_parent vs wrap_content.
On the internet people say that 320dp is the smallest android screen
Smallest device that I know is 240dp x 320dp which means 240dp is the smallest device size.
See following links for clarity
What is the difference between match_parent and fill_parent?
Supporting Different Screen Sizes
http://www.randomlytyping.com/blog/2014/2/9/matchparent-vs-fillparent
ViewGroup.LayoutParams
Update
Smallest device can have resolution of 180px x 240px = 240dp x 320dp
Related
I am a newbie Android developer and having a little problem. I have designed a screen layout for small screens (eg. 2.7" 240 x 320) with screen size qualifier it worked perfectly. Now when I designed layout for normal screens using smallest screen width qualifier. The app is working normal for normal screen phones but for small screen size (say 2.7"inches) the android is skipping the small screen layout and choosing the sw320dp qualifier layout.
So, is there any way so that android must choose small size screen layout (for 2.7"inches) and for normal screen phones it must choose sw320dp qualifier screen layout.
The swXXXdp resource qualifier is known as the smallest width qualifier. Using sw320dp tells the system to use those values for any device with a smallest width of at least 320dp. Therefore, if you're trying to create one layout for phones with exactly 320dp, and another layout for any phone larger than 320dp, you'd need to use a different number in your resource qualifier.
In your case, you could probably solve the problem by changing your directory to be layout-sw321dp.
In my experience, the common cutoffs I used were:
layout for small phones
layout-sw360dp for modern (larger) phones
layout-sw600dp for seven-inch tablets
layout-sw720dp for ten-inch tablets
How does the density dependent layouts work?
For landscape orientation only:
Two tablets -
One with mdpi density and 7inch screen size.
Other with tvdpi density and 7inch screen size.
I placed the layout1.xml in folder layout-large-land.
*The result: *
Tablet 1 with mdpi density working fine but Tablet 2 with tvdpi density layout disordered like shorter bitmap length and shorter margins for child layouts.
On account of getting this problem, I did the following change:
The layout1.xml now is in two different folders viz..
layout-large-land. and layout-large-land-tvdpi.
Now, Do I need to adjust (bitmap length and shorter margins for child layouts) manually for layout1.xml in layout-large-land-tvdpi OR will android auto adjust and set the tvdpi pixels by just seeing that its in a folder layout-large-land-tvdpi?
Your layout is mostlikely using absolute pixels, while, for sake of compatibility among variety of devices you should use device independent pixels. Also to avoid ending with blurry images (like upscalled from mdpi to tvdpi) you shall consider having your assets made for certain densities. Anyway, this is quite elementary subject and well explained in android docs: Supporting Multiple Screens
I have 3 layout folders in my project:
1. layout
2. layout-large
3. layout-small
and as of now i don't have anything in layout-small but layout has layouts with small dimensions and layout-large has layouts with large dimensions.
The problem is:
when i test my app on a 240x320 it uses layouts from layout
when i test my app on a 480x800 even now it uses layouts from layout
Is it because thought i have layout-large, 480x800 doesn't fall into large screens, hence uses the default layout folder?
If that is the case, how can i make layouts for Normal Screens there is nothing like layout-normal or layout-medium.
Moreover, if i design my layout for HVGA (320x480) it should work perfectly for WVGA800 (480x800) since they both fall under same screen size, only density changes. And i am using dp everywhere. Am i right?
any help appreciated.
When it comes to xlarge, large and small then it is depending on size(inches) not on dpi of your device
see below for specification
Additionally DPI is basically for Drawables while SIZE is for Layout.
Just use the following details it may work but i am not sure..
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Just try....
You should check this developer page out it helped me alot. http://developer.android.com/guide/practices/screens_support.html
Even if they have different resolution or screen size that doesnt mean that they have different pixel density. For example a large screen may have less pixel density than a smaller screen.
Another example would be the Samsung Galaxy tab which is 10.1 inch but is still mdpi-large and Nexus One which is less than 5 inch but uses hdpi.
Best of luck
I think I got what is going wrong with you........ lets try this.
suppose you are going to make the application compatible for 480x800 resolution.So for that first of all create two folder for it i.e.
1.layout-sw480dp this is for landscape.
2.layout-sw480dp-port for portrait mode.
Now,put all layout of the resolution of 480X800 in it.you see it will run easily on the particular resolution.
Note:- point here to be noted that for any device resolution let A X B. the name of the layout folder is goes like this.
1.layout-swAdp.
2.layout-swAdp-port.
here "A" is the screen resolution height value of device.
i hope it work for you.
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.
I am new to designing interfaces for Android. (I have gone through the Multiple Screens section in the Developer Guide.) What base resolution are you designing your screens for?
That is based on your app is for phone, or tablet, or both. Currently when designing layout for phone's app, there are three most basic resolution:
- 320dip x 480dip (normally 320px x 480px phone)
- 320dip x 533dip (normally 480px x 800px phone)
- 320dip x 569dip (normally 480px x 854px phone)
So when you design layout for phone's app, please remember:
1. Always use dip for width, height and sp for text size
2. A layout fit 320dip x 480dip screen will fit the other two
3. match_parent, wrap_content, gravity... are powerful Android XML layout attributes
4. Choose the orientation (landscape, portrait) carefully, normally an app requires only one orientation
The same goes for tablet's app, choose the most normal screens and create layout for the smallest one, and stretch the layout on bigger one.
But for both tablet and phone, you should use dimens.xml to store layout values. Reference here: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
Good luck with Android nightmare :)
Dont design for specific screen resolution!
Design for a range of devices either small screen, Medium screen or large screen.
Following are generic irrespective of your screen size.
Best layout is LinearLayout and RelativeLayout.
Bes metrics for Views 'dp' and for fonts 'sp'
Hope this helps!
I recommend base resolution for 320x480 pixel screen as this is supported by most number of devices. But you need to provide assets for hdpi (High Density), mdpi (medium density), ldpi (low density), xhdpi (xtra high density) specially images, buttons etc.