手机和平板电脑上的GUI不同,但应用程序相同 [英] Different GUI on phone and tablet, but same app
问题描述
我还必须为平板电脑和手机编写一个应用程序.这两个应用程序具有相同的功能,但是它们具有绝对不同的GUI.
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.
例如,电话在主屏幕上有2个按钮,而平板电脑上有5个按钮,因为我们想利用现有的空间.我知道,我能够定义不同的布局,具体取决于dpi,但是我应该如何在Activiies中处理布局?我认为,使用if(sdkVersion> = 11)bla..bla ...不能通过孔代码和孔项目工作!这是我必须使用多个应用程序支持的情况吗?
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 ?
已读文章: 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
推荐答案
将平板电脑布局放入res/layout-large/
.将手机布局放在res/layout/
中.给它们起同样的名字.您的活动将根据其运行的设备来加载正确的活动.调用findViewById()
检索额外的按钮时,如果看到返回的null
,请忽略它们.
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.
您可能需要在res/layout-large-land/
(平板电脑的风景),res/layout-xlarge/
(如果要处理10+平板电脑而不是5-9"范围内的东西),res/layout-small/
(如果您要处理< 3屏幕)等.
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.
这篇关于手机和平板电脑上的GUI不同,但应用程序相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!