1

I have developed a game in android,but i'm facing many problems with the screen sizes I heard that we should create separate folders like(layout-small,layout-normal,layout-large,layout-xlarge) in the res folder and should maintain all xml files in them.

But my confusion is how to retrieve particular xml from particular layout folder what is the code should be written in the Activity..? Please help me to solve this by an example. Thanks

  • Little help, on this page : http://developer.android.com/guide/practices/screens_support.html You'll find a "how to support multiple screen size" category. Reading it might answer some of your questions – Kevin Gilles Jul 31 '14 at 13:26

3 Answers3

1

I believe Android does it automatically. The operating system detects when the display is a certain orientation / size and uses the layout from the appropriate folder (if present) without you having to do anything apart from create the layout files.

1

you dont choose from which folder you read the xmls. Android does it for you depending on the dpi and the size of the screen its running on.

This is what helped me: http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html

  • your suggestion means a lot and its helpful for me thanx –  Jul 31 '14 at 13:48
  • I'm having a doubt here also if we place xml files in particular folders then what will be the main res/layout folder contents will do..? i mean to which type of screen size does it support..? –  Jul 31 '14 at 13:52
  • the simple layout is the normal layout and default one. It support medium devices. 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 this is from http://developer.android.com/guide/practices/screens_support.html. – antonis lambrianides Jul 31 '14 at 16:38
  • I was also very confused with all these aswell. You want to support a phone and a tablet? thats your goal? – antonis lambrianides Jul 31 '14 at 16:39
  • then follow the guide ive sent you. I made 1 layout, 1 layout-sw600dp and 1 layout-sw720dp and all 5 drawable folders(ldpi,mdpi,xxhdpi etc) and it works in both tablets and phones. Also in your drawable folders you must make different image sizes for each folder – antonis lambrianides Aug 01 '14 at 09:03
  • I also added this code but am not sure if it will work without this, you can try it out: – antonis lambrianides Aug 01 '14 at 09:05
0

No you don't need to create xml for each screen size. store your xml in your layout folder. and as per the size (hdpi, mdpi, xhdpi, xxhdpi) create images.(read developer guide for image size)

akshay bhange
  • 2,320
  • 2
  • 28
  • 46