在 Monodroid 应用程序中重用 Monotouch 代码 [英] Reusing Monotouch code in Monodroid app

查看:26
本文介绍了在 Monodroid 应用程序中重用 Monotouch 代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实施一个 Monotouch 应用程序,该应用程序最终将移植到 Monodroid.该应用程序只是 OData Web 服务的客户端.没有什么太花哨或性能关键.

I'm currently implementing a Monotouch application that will eventually be ported to Monodroid. The application is just a client to an OData Web service. Nothing too fancy or performance critical.

挑战在于尽可能多地重用代码.我知道 Monotouch 和 Monodroid 的 UI API 有很大不同,但我希望重用数据数据抽象和业务层.

The challenge is to reuse as much code as possible. I'm aware that the UI APIs for Monotouch and Monodroid are quite different, but I'm hoping to to reuse the data data abstraction and business layers.

由于我的 UI 层遵循 MVP 模式,我也希望通过编码每个视图的抽象表示来重用 UI 控制器.但是,我只能猜测这是否可行,因为我还没有被允许使用 Monodroid 测试版.

Since my UI layer follows the MVP pattern, I also hope to reuse UI controllers by coding an abstract representation of each view. However, I can only guess if this will work since I am not yet allowed to the Monodroid beta.

现在我的问题:

  • 您如何看待这种方法?这是一个好主意,还是会因为 iPhone 和 Android 之间 UI 概念的差异而导致应用程序平庸?

  • What do you think about this approach? Is this a good idea, or will it just lead to a mediocre application because of differences in the UI concept between IPhone and Android?

您能否就如何构建应用程序以最大限度地重用代码提供任何提示?

Can you offer any hints on how to structure the application to maximize code re-use?

谢谢,

阿德里安

推荐答案

您如何看待这种方法?这是一个好主意,还是会因为 iPhone 和 Android 之间 UI 概念的差异而导致应用程序平庸?

我会说后者,但您绝对可以重用大部分业务和领域对象.Monodroid 中使用了相同的 Mono Sqlite,因此您的应用程序的数据持久性部分(如果使用)是可重用的.

What do you think about this approach? Is this a good idea, or will it just lead to a mediocre application because of differences in the UI concept between IPhone and Android?

I would say the latter, but you can definitely re-use a large portion of your business and domain objects. The same Mono Sqlite is used in Monodroid, so the data persistence part of your app (if it uses that) is re-usable.

我不会费心创建中间层 UI - 两者完全不同.例如,在 Android 应用程序上,您有底部菜单,屏幕上可以包含 6 个按钮.在 iPhone 上,标签栏或工具栏中很可能没有 6 个按钮.为此制定一个通用模式对您没有多大帮助.

I wouldn't bother creating a middle layer UI - the two are completely different. For example on Android apps you have the bottom menu, which can contain 6 buttons on screen. On the iPhone you are more than likely not to have 6 buttons in a tab bar or toolbar. To make a common pattern for that won't help you much.

另一个例子是 ListViews (UITableViews).他们完全不同.正如您所期望的,Monodroid 实现忠实于其丑陋的 Java 姐妹.在 Android 上,您不必使用 Apple 强加给您的大量间接寻址,而只需使用一个简单的 ArrayAdapter 作为数据源 - 为更复杂的布局进行子类化.

Another example is ListViews (UITableViews). They're completely different. As you'd expect the Monodroid implementation is faithful to its ugly Java sister. On Android you don't have to use the huge tangle of indirection that Apple force upon you, but just a simple ArrayAdapter as the data source - subclassed for more complicated layouts.

另一件需要注意的重要事情是Android 没有一种屏幕尺寸.您为 3 种不同的屏幕密度创建图像.字体大小不是绝对的.

Another important thing to note is Android doesn't have one screen size. You create images for 3 different screen densities. Font sizes aren't absolute.

Android 为您提供类似于 XAML 和 Web 的布局机制,在 iPhone 上您就没有那么幸运了(或者更幸运,取决于您如何看待它),因为一切通常都是绝对定位的(他们可以像往常一样做到这一点)320x480).

Android provides you with layout mechanisms similar to XAML and the web, on the iPhone you're not so lucky (or more fortunate, depending how you view it) as everything is generally absolutely positioned (they can do this as it's always 320x480).

我认为您已经大部分时间覆盖了单独的数据层并坚持使用控制器.如果没有看到您的应用,很难说重用控制器有多么容易(无论您使用 UITableViews 还是自定义 uis),但 Android 的开发速度要快得多,我认为这应该是一项快速任务.

I think you've got most of covered with separate layers for the data and sticking to controllers. Without seeing your app it's hard to say how easy it will be re-use the controllers (whether you use UITableViews or custom uis), but Android is so much faster to develop with I think it should be a quick task.

(我正在使用 Monodroid 预览版,并且还有一个 MT 应用程序)

这篇关于在 Monodroid 应用程序中重用 Monotouch 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆