Android Universal App Approach -
i want develop universal app . novice approach .that means single apk both tablet , phone application . had go through
my aim build different ui tablet , phone inside single apk .
i had read getting app ready jelly bean , nexus 7 . article mention that
res/layout/activity_home.xml take advantage of space on 7” screen might provide alternative layout: res/layout-sw600dp/activity_home.xml sw600dp qualifier declares these resources devices have screen @ least 600dp available on smallest side. furthermore might provide different layout 10” tablets: res/layout-sw720dp/activity_home.xml
that means can use different layout different device . confuses me
edit 1 :: scenario
suppose
if phone ui layout contains one-view pager , tablet ui layout contain two-view pager .
how can achieve ?? in article says designe different layout same name different screen , keep corresponding folder . doubt arise exceptions if try initialize widget component of tablet layout when app running in phone .
edit 2 : idea came mind determine type of device using ie tab or phone .
determine if device smartphone or tablet?
then avoid initialization of widgets if app phone . there better way ??
edit 3 : application support 2.3 higher versions
if layouts tablet holds additional widgets compared phone layout .how initialize , use . hope understood need . please clarify doubt
when face problem, create following structure.
res/layout res/layout-sw600dp
then distinguish values , other resources,
res/values res/values-sw600dp res/values-sw720dp
you noticed there one layout directory , two values directory specify margins , paddings , other resources. single layout can used 7" 10" tablet. scenario, can define layout-sw720dp. did due reduce compilation time of layouts.
i have different layouts in phone , tablet. example, have listview in first screen, when user click on item, open other activity , there detailview that. in tablet, have left side listview , right side detailview.
so so, in values/strings, place following code,
<bool name="istablet">false</bool>
and same tablet values-sw600dp/strings
<bool name="istablet">true</bool>
now, come part of coding. have splash screen , has common layout. display common screen. when user click on button, check whether tablet or not. check it,
boolean istablet = getresources().getboolean(r.bool.istablet);
you have flag indicate whether application running on phone or tablet.
i have created 2 packages,
com.phone com.tablet
then per flag, direct activity phone package , tablet package.
example,
if(istablet) startactivity(this,tabxyz.class); else startactivity(this,phxyz.class);
and approach has solved problem.
Comments
Post a Comment