8

I am trying to make a application in Android. I want that it should be able to run on multiple phones of different screen sizes, so i studied support multiple screen on developers and according to that i have to create 3 different xml files for supporting three different screen sizes and also 3 different types of images for each type of xml file. But on a blog i get the idea of doing this by using current screen size method. So i am confused what i should do. means which is optimized and performance increasing way. And which one will be more perfect for supporting all types of screen(except extra large screens)

  • 1
    I suggest you create the three different layouts for each type of screen format. This is by default the way in which Android is built to handle the different screen sizes for the numerous devices. It also allows you to keep your styling and design separate from your code. – ASceresini Apr 30 '12 at 08:57
  • so android will automatically pick the correct xml file according to phone screen size or do i need to modify java code or create 3 types of java files –  Apr 30 '12 at 08:59
  • android will automatically pick the correct layout to use for the devices type – ASceresini Apr 30 '12 at 09:01
  • you can use different xml based on device for res folder layout-small(320x240,240x320) to design small screen devices like layout-medium(320x480),layout-large and layout-xlarge and so on...! – Dinesh Apr 30 '12 at 09:01
  • and what about images i need to create three types of images in three drawable folders(same name in each folder) and android will pick the image according to layout –  Apr 30 '12 at 09:03
  • if you want to support higher res images for higher res screens yes – ASceresini Apr 30 '12 at 09:20
  • possible duplicate of [multiple screen support in android](http://stackoverflow.com/questions/7453982/multiple-screen-support-in-android) – arpit Aug 06 '15 at 06:06

4 Answers4

5

Defining height, width and other parameters in the XML file is the better option rather than on run time. Because XML files works as metadata (data carrier) to the activity and avoids alot of confusion when onCreate mothode in called. Plus, create different folders for image quality (hdpi,xhdpi,ndpi,ldpi)

7 inch device use mhpi 10 inch devices use hdpi and xhdpi While NEXUS tabs use hdpi and xhdpi irrespective of their size. Mobiles use ldpi and ndpi.

Beauty lies here is that android device automatically pick-p the suitable content when found, i.e layout and image. If not found it would first search other Layout folders,e.g a layout not found in x-large folder then it will search in large,then medium, small, which one of them suits the best ,(if a layout is not found in its respective folder).

Nexus will create alot of trouble for you. To check how your layout would look on different devices, try using the options, which tells you how it would look on that device with those height width, present in the Graphical (view of a ) layout.

Fahad Ishaque
  • 1,916
  • 1
  • 17
  • 21
  • I have different layouts for each, but still not working. http://stackoverflow.com/questions/34378238/landscape-mode-for-app – Ruchir Baronia Dec 20 '15 at 09:04
1

You can use three different layouts for different screen sizes ,and android will pick the suitable layout , but Using three different layouts for each type of screen format will not be a good idea , because it will cause problem in handling all layout , if screens are less then its fine but if number of screen increases it will get difficult . Like if you forget to add change in one of the screen size it shall crash with any exception . What you can do is keep images of different size in different folders and practice layout to make standard in one layout by using layout weights , and margins in in dp .

See my this answer

Table Layout spacing issues and check this layout will look similar for all screen sizes.

Community
  • 1
  • 1
Avi Kumar
  • 4,403
  • 8
  • 36
  • 67
  • no that issue is totally different which link you are telling me. I have to build a app which runs similar on 2inch phone as well as 5.4 inch note. And i am tired of maintaining dp according diff size because either i can set dp according to small screen or large screen. If i set according to large screen to solve space issues then bottom part of app doesn't appear in small screen i don't wanna use scrollLayout. So now i think the only way remaining is to create different xml for each screen –  Apr 30 '12 at 10:23
  • @Vickie i was not telling you about the issue wanted to let you know about layout weight and using them , just copy paste the code and see the buttons shall look similar in all layouts – Avi Kumar Apr 30 '12 at 10:33
  • earlier i was also doing the same by creating different layouts but it is a tedious task , so just wanted to show you an example what we should do – Avi Kumar Apr 30 '12 at 10:35
  • I have different layouts for each, but still not working. http://stackoverflow.com/questions/34378238/landscape-mode-for-app – Ruchir Baronia Dec 20 '15 at 09:04
0

If your design is same for all screens sizes you can use dp and have only one xml for all screens. But you should support icons for all screens.

someUser
  • 965
  • 12
  • 24
  • yeah it is same and i am using dp but it is not working exactly, mean in large screen it shows the bottom part of image but in small it doesn't –  Apr 30 '12 at 09:04
  • I used dp in my whole project and all were perfect. Maybe you have some mistakes. – someUser Apr 30 '12 at 09:07
  • no u r not getting this, dp works fine on emulator with display of large but in small it doesn't. –  Apr 30 '12 at 09:12
0

I think it's less confusing David Ohanyan way, but forgot to say something... Whenever you can, use styles in your xx_layout, images, etc, so you'll have 1 layout.xml and 3 styles files inside folders: values, values-small, layout-large.

At least for me, it's less confusing than opening 30 different layout files.

Jordi
  • 616
  • 2
  • 9
  • 16