2

I am building a app, want to run it on multiple screens exactly same in looking. So i tried the worst(according to me) and best way (according to developers) to create three separate folder of xml file to support large, medium and small screen. My folders name are layout(according to developers it is default and will work for medium size screen WQVGA 400), layout-large(WVGA800) and layout-small(QVGA). But however if i change something in a file(which is in all three folders by same name) in layout folder(default one) that change is applying to both large and medium but not applying to small. No matter what i am changing in layout large folder's xml file that doesn't apply to large screen display but changes of layout-small works for small screen. So i want that how can i configure large screen xml separately and medium screen xml separately that they both doesn't affect each other.

  • you can create folder layout-noraml,layout-large and layout-xlarge under project for separate xml file...! – Dinesh May 03 '12 at 06:44
  • i created different layout folders but on developers they say layout works for normal screen, so if you have tried layout-normal then tell me, cz i have to copy paste lots of file –  May 03 '12 at 07:11
  • in supporting all screens it's not always necessary to create all layout it's also depend on what you are doing in your layout. – Herry May 03 '12 at 07:13
  • you need layout separate for normal screen? – Dinesh May 03 '12 at 07:15
  • @Dinesh no i was asking to you that if you have tried that separate layout-normal folder suggestion then tell me –  May 03 '12 at 07:19
  • @herry what do you mean by what you are doing i am just making a linear layout with 2 linear layout and 1 relative layout and few buttons inside –  May 03 '12 at 07:21
  • design all layout's in scale in dp like width and height and don't use scale px like width and height that's all...! – Dinesh May 03 '12 at 07:27
  • @vickie if you are just using `LinearLayout` then make it work with use of weight and as suggest by @Dinesh use dp . – Herry May 03 '12 at 07:29
  • @dinesh again appreciate your help but as i told you earlier i have read developers page support screens, so you think still i am not using that. hows that possible? I am using dp or dip throughout my whole project but result is same – Vikas Gupta May 03 '12 at 07:32
  • @herry i dnt have more idea of weight can yo post me a easy tutorial of that – Vikas Gupta May 03 '12 at 07:32
  • try this link for different layout explanation http://developer.android.com/guide/topics/ui/layout-objects.html – Dinesh May 03 '12 at 07:41

3 Answers3

1

you can use following folder structure in your android project .

 1.layout This Use For Default Layout Files  // layout for normal screen size ("default")
   2.layout-land For Use in Landscape Mode
   3 layout-large     // layout for large screen size
   4.layout-large-long
   5.layout-large-long-land
   6.layout-large-notlong
   7.layout-large-notlong-land
   8.layout-ldpi
   9.layout-normal-long
   10.layout-normal-long-land
   11.layout-normal-notlong
   12.layout-normal-notlong-land
   13.layout-small   // layout for small screen size
   14.layout-small-land
   15.layout-xlarge      // layout for extra large screen size
   16.layout-xlarge-land   // layout for extra large in landscape orientation
Herry
  • 7,037
  • 7
  • 50
  • 80
  • 1
    you must be kidding man, how can i create so many xml file and handle them. it looks like a road to hell –  May 03 '12 at 07:18
  • as i said in comment over your question ,it is not necessary to use such kind of layout structure it will depend on your requirement and what you have design in your layout file. – Herry May 03 '12 at 07:20
  • sorry mate, i read that later. if you want then i can post source code of each file, i found that unnecessary that's why i didn't paste that. –  May 03 '12 at 07:22
  • yes in that case i don't need that ,but thing is that you can refer table 3 from this http://developer.android.com/guide/practices/screens_support.html#screen-independence.for normal screen if you have declare layout and for large screen if you don't have declare any layout then it will first go for default layout which is `layout` folder – Herry May 03 '12 at 07:25
  • i defined one xyz.xml file in all three folders. but if i add a button in xyz.xml of layout folder. then just tell me in which screens that button should appear –  May 03 '12 at 07:29
  • it should appear for normal screen size. – Herry May 03 '12 at 07:33
  • no but it is also appearing in large screen. This is one of my big problem. changes of normal screen shouldn't appear in large screens –  May 03 '12 at 07:35
  • yes in this case you are right but do you have declare same xml that use in layout in this folder `res/layout-large/my_layout.xml` have you this thing also. – Herry May 03 '12 at 07:39
  • i didn't get your last comment totally. but yeah i have declared my xyz.xml file in layout-large folder also, but in that file i am not adding a button. so why it is appearing on the large screen –  May 03 '12 at 07:45
  • in which you have test by create Emulator or in real device. – Herry May 03 '12 at 08:17
  • @Vickie have you care fully look in to Table No 3 in this http://developer.android.com/guide/practices/screens_support.html .Because as you are facing problem your Emulator with size WVGA800** (480x800) is not picking layout from res/layout-large/ and it is right it will pick layout from normal or default because emulator that you have it's have density :240 that means it come in normal screen hdpi according to table NO 3 ,So now you may clear why it happen. – Herry May 03 '12 at 09:32
  • thanks a lot man, it helped me really a lot.. But one more thing, is there any chance that emulator WQVGA400 will pick its images from drawable-ldpi –  May 03 '12 at 10:08
  • if emulator that have with density :120 (Low) that will fetch image from drawble-ldpi folder.You can accept if my answer help you. – Herry May 03 '12 at 16:30
  • sorry still it is not acceptable, but i'll surly upvote your answer for your precious time you gave me –  May 04 '12 at 10:12
  • The most useful part of the "multiple screens" page i found was: http://developer.android.com/guide/practices/screens_support.html#range specificaly, that "So, each generalized screen size above has an associated minimum resolution that's defined by the system". So using the small,normal,large,xlarge set up seems the best option. As jordi says, i think the best approach is one layout file and then several styles and drawables. I've actually created python script i can customise to generate the various drawable resource xml files i need. – Sam Jul 20 '12 at 11:57
  • So android will automatically find the folder to use? – Ruchir Baronia Nov 19 '15 at 01:38
1

Depending the project, the easiest way is creating one 'styles.xml' file for each screen size inside values folders:

values  //default
values-small
values-large
varlues-xlarge

Then you only need to manage 4 different files with the styles (changing length, margins, letter sizes, etc). You can also add the other configurations @Herry said (large, land,..) if needed.

Jordi
  • 616
  • 2
  • 9
  • 16
0

"But however if i change something in a file(which is in all three folders by same name) in layout folder(default one) that change is applying to both large and medium but no applying to small."

Answer to this is, "Since you have different layout folder for small, medium and large screen then change made to large screen won't reflect for small screen. You will have to make the change in small-screen layout file as well.

But, as you said, your UI for all different sizes of devices is same then you should never create different layout folders. Only one layout folder is enough, Android will take care of rendering on different screen sizes during run time. Also go through this link http://developer.android.com/guide/practices/screens_support.html. After reading this you will be able to make your own decision on the type UI design you want for your application.

Nate
  • 30,286
  • 23
  • 113
  • 184
Sushil Kadu
  • 439
  • 3
  • 5
  • Thanks Sushil, for not applying to small i know why it was not applying. By that line i was telling that why it is applying to large screen and please also check your link again where they suggest you to create different folders. –  May 03 '12 at 07:16