5

我也必须为平板电脑和手机编写应用程序。这两个应用程序具有相同的功能,但它们具有完全不同的 GUI。

例如,手机在主屏幕上有 2 个按钮,但平板电脑将有 5 个,因为我们想使用我们现有的空间。我知道,我能够定义不同的布局,取决于 dpi,但我应该如何处理 Activiies 中的布局?我认为,使用 if(sdkVersion >=11) bla..bla... is not will work through the hole code and the hole project!这是我必须使用多个应用程序支持的情况吗?

阅读文章: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

我不明白我应该如何处理这个问题......如果你能帮忙,谢谢

4

1 回答 1

6

将您的平板电脑布局放入res/layout-large/. 将您的手机布局放入res/layout/. 将它们命名相同。您的活动将根据它们运行的​​设备加载正确的活动。当您调用findViewById()以检索额外的按钮并看到您null返回时,请忽略它们。

res/layout-large-land/您可能需要在诸如(平板电脑的景观)、res/layout-xlarge/(如果您想以不同于 5-9 英寸范围内的东西的方式处理 10 多英寸平板电脑)、res/layout-small/(如果您想处理 <3 英寸屏幕)等位置进行额外的布局。

于 2011-09-17T17:51:57.093 回答