Android: support multiple screens

后端 未结 4 1975
無奈伤痛
無奈伤痛 2020-11-30 13:16

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 deve

相关标签:
4条回答
  • 2020-11-30 13:22

    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.

    0 讨论(0)
  • 2020-11-30 13:26

    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.

    0 讨论(0)
  • 2020-11-30 13:40

    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.

    0 讨论(0)
  • 2020-11-30 13:40

    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.

    0 讨论(0)
提交回复
热议问题