手机和平板电脑上的 GUI 不同,但应用程序相同
我还必须为平板电脑和手机编写一个应用程序。这两个应用程序具有相同的功能,但它们的 GUI 完全不同。
例如,手机的主屏幕上有 2 个按钮,但平板电脑有 5 个按钮,因为我们想利用现有的空间。我知道,我可以定义不同的布局,具体取决于 dpi,但是我应该如何处理 Activity 中的布局?我认为,使用 if(sdkVersion >=11) bla..bla... 不会通过漏洞代码和漏洞项目起作用!这是我必须使用多个应用程序支持的情况吗?
读过的文章: 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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的平板电脑布局放入
res/layout-large/
中。将您的手机布局放入res/layout/
中。将它们命名为相同。您的活动将根据运行的设备加载正确的活动。当您调用findViewById()
来检索额外的按钮,并发现返回null
时,请忽略它们。您可能需要在
res/layout-large-land/
(平板电脑横向)、res/layout-xlarge/
(如果您想处理 10 个以上“平板电脑与 5-9 英寸范围内的设备不同),res/layout-small/
(如果您想处理 <3” 屏幕)等。Put your tablet layouts in
res/layout-large/
. Put your phone layouts inres/layout/
. Name them the same. Your activities will load the right ones based upon the device they run on. When you callfindViewById()
to retrieve the extra buttons, and see that you getnull
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.