Universal App for both tablets+handsets

我的梦境 提交于 2019-12-22 01:10:24

问题


I am developing a single application for both tablets and for handsets..My app is currently running fine on handsets(as according to layouts and all)..but i have no idea for how to distinguish it for handsets/tablets. I have seen some of the answers in Stackoverflow.com too, in which some people answered that use different layout-large,layout-xlarge.

but if the layout differs and we follow the above scenario,then in programming,it is written setcontentView(R.layout.---).

So we have to mention here also that setContentView(R.layout-large.---)..I am so confused with this..Can anyone suggest me something...


回答1:


you only need to name the folder differently those contain same nameLayout.xml

like so

--layout
   -- myLayout.xml
--layout-large
   -- myLayout.xml
--layout-xlarge
   -- myLayout.xml

on code, you only need to use

secContentView(R.layout.myLayout);

android will find the right one for you.




回答2:


The android os will select the appropriate folder based on the device dimensions and other properties.

So you can keep the resource name same in all the folders and android will pick from the appropriate folder.



来源:https://stackoverflow.com/questions/7735318/universal-app-for-both-tabletshandsets

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