Multiple screen support do we need different layouts for each screen

北战南征 提交于 2019-12-17 19:56:12

问题


For Multiple screen support do we need different layouts for each screen which goes in hdpi, ldpi and mdpi folders, I read this on android site, but not sure how to implement this one.

Thanks Max


回答1:


The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.

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
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

This information are already given at Android developer site: http://developer.android.com/guide/practices/screens_support.html

Alternative drawables => Screen densities:




回答2:


Screen resolution (screen density) does affect the appearance of components. To support different screen densities, similarly to the solution given by Ash, have the following folders:

  • res/values-ldpi for low-density (ldpi) screens (~120dpi)
  • res/values-mdpi for medium-density (mdpi) screens (~160dpi)
  • res/values-hdpi for high-density (hdpi) screens (~240dpi)
  • res/values-xhdpi for extra high-density (xhdpi) screens (~320dpi)
  • res/values-nodpi for all



回答3:


Let's assume that you have a default, good-looking layout in the layout folder. In most cases, Android will be able to adjust it properly. In my practice, only large screens require a new layout parameters.

To avoid layout duplication, we use the following layout structure:

res/layout/foo.xml                      -- layout file
res/values/foo_styles_default.xml       -- default styles (component sizes, margins, etc.)
res/values-large/foo_styles_large.xml   -- styles for large screen
res/values-xlarge/foo_styles_xlarge.xml -- styles for very large screen

Screen-size-dependent parameters in the 'foo.xml' layout are set via the 'style' attribute, thus allowing us to avoid creating multiple layout files.




回答4:


As per my observation most of screen will work for different screen size. Please test for app in different screen sizes and if you find issue than place layout in specific folder as diffined above.



来源:https://stackoverflow.com/questions/7414178/multiple-screen-support-do-we-need-different-layouts-for-each-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!