Android - 需要帮助设计带有表格布局或列表视图的屏幕
我目前正在开发一款 Android 应用程序,该应用程序将与其姊妹版 iPhone 原型相对应。
我的任务是从 Android 中的 iPhone 应用程序的设计模型中重新创建屏幕,如下所示:
在活动中复制此屏幕的最佳布局/视图是什么?
谢谢。
I am currently developing an Android app that is to be a counterpart to its sister iPhone prototype.
My task is to recreate the screen from a design mockup from the iPhone app in Android, as shown here:
What would be the best layouts / views to use for replicating this screen in an activity?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题并没有澄清一些事情。另外,我不同意特德·霍普的回答。我相信他假设药物将被静态填充,或者类似的东西。
从您的应用程序的外观来看,我假设您将动态填充内容,可能一次填充多种药物,或者根本不填充药物。通过 iPhone 模型中的箭头,我还假设您会想要根据所选药物执行操作。
尽管如此,我还是会使用
ListView
。我的一般概念(我可能会使用的概念)是这样的:你有你的数据源,并使用 Loader/LoaderManager/等等。将其填充到
Cursor
中。我会将这个光标提供给一个CursorAdapter
(可能是一个SimpleCursorAdapter
),通过查看该 UI 概念,这似乎很可能并且很容易 --- 不需要自定义适配器本身的一部分)。最后,该适配器将在ListView
中使用。这相当简单,不需要太多代码(ListView-SimpleCursorAdapter-Cursor 的东西,数据逻辑当然是自定义的)。然后,您可以使用适当的
ListView
侦听器 IIRC 来管理每次点击。并根据所选项目采取相应行动。例如,我猜测用户会通过startActivity
查看每种药物的详细信息。然而,正如我所说,如果你有固定数量的药物(这里说的是一位经验丰富的前白血病患者,所以我总是假设药物差异很大!),单个
TableLayout
就可以了,但我觉得事实并非如此。啊,关于每个组件/医学的布局,正如我所说,一个简单的布局就可以了。可能是水平方向的 LinearLayout。同样,使用
SimpleCursorAdapter
实现非常简单。Your question does not clear some things up. Also, I disagree with Ted Hopp's answer. I believe he is assuming that the medications will be filled statically, or something like that.
By the looks of your app, I assume you will be filling stuff dynamically, probably with many medications at once, or no medication at all. By the arrows in the iPhone mock-up, I also assume you will want to perform actions depending on the medication selected.
All that said, I would use a
ListView
. My general concept (the one I'd probably use) would be like this:You have your data source, and use a Loader/LoaderManager/etc. to fill that into a
Cursor
. I'd feed this cursor to aCursorAdapter
(perhaps aSimpleCursorAdapter
, which seems likely and easy by looking at that UI concept --- won't need to customize the adapter part itself). Finally, this adapter would be used in theListView
. This is fairly easy and won't take much code (the ListView-SimpleCursorAdapter-Cursor stuff, the data logic is certainly custom).You can then manage each of your clicks using the proper
ListView
listeners, IIRC. And act accordingly depending on the item selected. I'm guessing that the user would, for example,startActivity
to see a detail about each medication.However, as I said, if you have a fixed number of medications (here says an experienced former leukemia patient here, so I always assume medications vary widely!), a single
TableLayout
would do, but I feel that's not the case.Ah, and about the layout for each component/med, as I said, a simple layout would do. Probably a
LinearLayout
with horizontal orientation. Again, very simple to implement with aSimpleCursorAdapter
.此处有一个很好的示例,说明如何使用自定义行视图执行此操作。这可能是最干净的方法。
最接近的内置小部件是 TableLayout。查看 Hello Views 教程项目,了解以下示例这在行动中。您可能想将其包装在 ScrollView 中。
There's a nice example of how to do this with a custom row view here. This is probably the cleanest way to go.
The closest built-in widget for this is a TableLayout. Take a look at the Hello Views tutorial project for an example of this in action. You might want to wrap it in a ScrollView.
正确的方法很大程度上取决于需求。在我看来,你(至少)有几个选择:
正如 David 指出的,如果你有一组固定的数据,TableLayout 是最合适的,但你也可以通过添加子视图来使其动态工作。 。使用 TableLayout 的好处主要是列的内置实现,包括基于内容的动态列大小调整。缺点是缺乏内置的动态支持,尤其是在处理大型数据集时。
ListView 更适合动态和大型数据集,但有不支持列的限制。 Ted 的链接允许您模拟列,但与 TableLayout 不同的是,这些列具有固定宽度(以父级宽度的百分比表示)。列的大小不根据内容而定。您可能会尝试做一些事情来测量所有孩子,但这会很棘手。尝试处理 ListView 中的标题也可能会有点烦人,尽管稍加搜索,您就会发现大量资源可以帮助您解决此问题。
第三个选项是滚动您自己的 AdapterView 或 AbsListView。当然,这涉及大量的工作,但您可以看看 TableLayout 的工作原理并根据内容调整列的大小。这也将使您获得对适配器的支持以及随之而来的所有好处。但这可能是一项相当大的工作,尤其是根据内容调整列的大小。
考虑您的列是否必须调整大小以适应其内容。
The right approach is highly dependent on the requirements. As I see it, you have (at least) a few options:
As David noted, the TableLayout is most appropriate if you have a fixed set of data, but you can make it work dynamically too simply by adding child views. The benefit of using the TableLayout is mainly a built-in implementation of columns, including dynamic column sizing based on contents. The down-side is the lack of built-in dynamic support, especially when working with large data sets.
A ListView is a better fit for dynamic and large data sets, but comes with the limitation of not supporting columns. Ted's link lets you simulate columns, but unlike TableLayout these columns have a fixed width (in percentage of the parent's width). The columns are not sized based on content. You could potentially try to do something to measure all the children, but it'd be tricky. It can also be mildly annoying to try to deal with headers in a ListView, though with a little searching you'll find plenty of resources to help you with this.
The third option is to roll your own AdapterView or AbsListView. Of course this involves a significant amount more work, but you could take a look at how TableLayout works and resize the columns based on the content. This would also get you support for adapters and all the benefits that come along with that. This is probably quite a bit of work though, especially resizing the columns based on content.
Consider whether your columns must resize to fit their content or not.