Universal App for both tablets+handsets

2019-04-16 21:31发布

问题:

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.