user1343631
user1343631

Reputation:

Android: support multiple screens

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)

Upvotes: 8

Views: 1847

Answers (4)

Fahad Ishaque
Fahad Ishaque

Reputation: 1926

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.

Upvotes: 5

Avi Kumar
Avi Kumar

Reputation: 4433

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.

Upvotes: 1

Jordi
Jordi

Reputation: 616

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.

Upvotes: 0

someUser
someUser

Reputation: 967

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.

Upvotes: 0

Related Questions