Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different GUI on phone and tablet, but same app

I have to write an app for tablet and for phones too. The two app has the same functionality, but they have absolute different GUI.

For example the phone have 2 button on the main screen, but the tablet going to have 5, because we would like to use the space what we have. I know, I˜m able to define different layouts, depends on dpi, but how should I handle the layout-s in the Activiies? I think, to use if(sdkVersion >=11) bla..bla... is not will works through the hole code and the hole project! Is this the situation where I have to use multiple application support ?

readed articles: http://developer.android.com/guide/practices/screens_support.html

http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

http://developer.android.com/guide/market/publishing/multiple-apks.html

I don`t understand how should I handle this problem... please if you able help , thx

like image 253
narancs Avatar asked Sep 17 '11 16:09

narancs


1 Answers

Put your tablet layouts in res/layout-large/. Put your phone layouts in res/layout/. Name them the same. Your activities will load the right ones based upon the device they run on. When you call findViewById() to retrieve the extra buttons, and see that you get null back, ignore them.

You may need additional layouts in places like res/layout-large-land/ (landscape for tablets), res/layout-xlarge/ (if you want to handle 10+" tablets differently than stuff in the 5-9" range), res/layout-small/ (if you want to handle <3" screens), etc.

like image 170
CommonsWare Avatar answered Sep 30 '22 17:09

CommonsWare