Android conditional layouts for phones:tablets

别来无恙 提交于 2019-12-10 09:36:49

问题


I am making an app that is readily available and MOSTLY used on phones, but would be CONVENIENT to use on a tablet if available.

I am familiar with landscape/portrait layouts for the separate XML files, but what about for the different resolutions? This is also an issue for phone-only applications, what is the best way to have scalable layouts.

I use the dip values which are density independent but not as effective as just using percentages that will scale your layout effectively.

I also hardcode the XML. I IMAGINE that I could programmatically generate the layout by checking the screen width and height ON EVERY ACTIVITY, but tell me there is a better way?


回答1:


You can provive extra layouts by specifying the screen size (small, normal, large and xlarge) in the same way you specify layouts for portrait or landscape.

These are some examples taken from the android documentation related to this subject

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

The book The Busy Coder's Guide to Android Development has an excellent explanation about this subject.



来源:https://stackoverflow.com/questions/6669836/android-conditional-layouts-for-phonestablets

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