I have created a layout in my xml file and have a LinearLayout that is displayed at the top of the activity. I have set its width to fill_parent
and its height to 54dp
. The height of the layout looks good on devices with bigger screens like Samsung Galaxy, but on smaller devices it looks too big. Is there anyway that the layout will have different height on different screen sizes? I am guessing that this might be achieved by dp, dip, etc. but I'm not sure as to what exactly they do
Asked
Active
Viewed 171 times
0

Ankush
- 6,767
- 8
- 30
- 42
-
you can find more info about ther dp,dip etc here http://stackoverflow.com/questions/2025282/difference-of-px-dp-dip-and-sp-in-android – Ali Imran Dec 05 '12 at 06:34
2 Answers
0
make layout-normal-hdpi, layout-normal-mdpi and layout-normal-xhdpi folders and copy the same xml in all the three folders than set the different height on each xml as per the devices. This is the standard technique which is been followed. Try this you will surely get desired result.

Nitin Bathija
- 800
- 3
- 12
- 24
-
ok. But I have around 15 different layout files and creating 30 more will be a very tedious process. Is there any other, more elegant way, of solving this – Ankush Dec 05 '12 at 06:40
-
Its not necessary that you create all the xml layout files. You will have to just create which those layout's which are completely dynamic and which are static layout, those you can keep in default layout folder. – Nitin Bathija Dec 05 '12 at 06:47
-
I understand. But the thing is that I have this layout in every single layout file. Its kinda like a navigation bar which tells the user which screen is he on – Ankush Dec 05 '12 at 06:49
-
Ok so you can do this thing is to make one xml which will contain only the navigation part of your layout like navigation.xml and than include that xml file where ever you need in your layout files by using include widget but make sure that you keep this navigation.xml in all different layout folders. With this you don't need to keep all the remaining layout's in all folders. Try this. – Nitin Bathija Dec 05 '12 at 06:57
-
but my navigation bar has different text for each activity. Also some activities have a button on the navigation bar and some don't – Ankush Dec 05 '12 at 07:04
-
Just include navigation.xml and than create TextView or buttons where you need but keep tham in a Linear or RelativeLayout and adjust the margins as you need.. Else programitically you can hide the textview and buttons on different activities as per your need. – Nitin Bathija Dec 05 '12 at 07:10
0
Hope this will help you...
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
Low density Small screens QVGA 240x320
res/layout-small-ldpi
res/layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
res/layout-ldpi
res/layout-land-ldpi
Medium density Normal screens HVGA 320x480
res/layout-mdpi
res/layout-land-mdpi
Medium density Large screens HVGA 320x480
res/layout-large-mdpi
res/layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
res/layout-hdpi
res/layout-land-hdpi
Xoom (medium density large but 1280x800 res)
res/layout-xlarge
res/layout-xlarge-land
Comment me for any query...

Shreyash Mahajan
- 23,386
- 35
- 116
- 188