Android UI:新活动还是新布局?
我正在为应用程序设计界面,以在 TableLayout
中显示从数据库中提取的一些数据。目前,默认视图是纵向视图,由下拉菜单和三列表格组成。当用户切换到横向时,微调器及其选择可以保持不变,但我将显示一个完全不同的表格(不同的列标题和更多列)。
值得注意的是,当用户从下拉菜单中选择一个选项时,就会调用数据库。从此调用检索到的所有数据都存储在 ArrayList 中,并且此 ArrayList 还包含将以横向模式显示的信息。我的问题是,将景观设计创建为全新的活动,还是简单地将其定义为新的布局,会更好吗?在我看来,创建一个新活动需要大量冗余代码,并使用户不必要地等待另一个 Web 服务调用。
这是纵向布局:
这是横向布局:
注意:纵向模式的微调器也会出现在横向布局中,忘记将其包含在图片中
I'm designing the interface for an application to display some data pulled from a database in a TableLayout
. Right now, the default view is portrait orientation which consists of a drop down menu and a table with three columns. When the user switches to landscape orientation, the spinner and its choices can stay the same, but I am going to be displaying an entirely different table (different column headings and more columns).
Something worth noting is that when the user picks an option from the drop down menu, a call to the database is made. All the data retrieved from this call is stored in an ArrayList
, and this ArrayList
also contains the info that will be displayed in landscape mode. My question is, would it be better to create the landscape design as entirely new activity, or simply just define it as a new layout? It seems to me that making a new activity would require a lot of redundant code and making the user wait unnecessarily for another web service call.
Here is the portrait layout:
Here is the landscape layout:
Note: the spinner from portrait mode will be present in the landscape layout as well, forgot to include it in the picture
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 可以非常轻松地为不同方向创建单独的布局文件。如果您只需将一个
layout-land
文件夹添加到您的项目中,并添加一个与纵向布局文件同名的新布局文件(但具有您需要的不同 UI 元素),那么操作系统本身将自动根据方向切换布局。您需要做的就是检查
onCreate(...)
中的方向并将其保存为布尔值(例如isPortrait
),然后负责更新 UI 的每个方法都可以简单地检查以确定需要填充/更新哪些组件(表列等)。Android makes it extremely easy to have separate layout files for the different orientations. If you simply add a
layout-land
folder to your project and add a new layout file with the same name as the one for portrait (but with the different UI elements you need) then the OS itself will automatically switch layouts depending on orientation.All you need to do is check orientation in
onCreate(...)
and hold it as a Boolean (isPortrait
for example) then each method responsible for updating the UI can simply check that to determine what components (table columns etc) need to be populated/updated.我认为从纵向变为横向时进行新活动有点太多了。您应该只使用 CSS3 媒体查询来更改表格的显示方式。在景观中使用浮标或透明物显示更多信息。使用响应式布局原则: http://www.alistapart.com/articles/responsive-网页设计/
I think having a new activity when changing from portrait to landscape is a bit too much. You should just use CSS3 media queries to alter how the table is displayed. Show more information with the use of floats or clears when on landscape. Use the responsive layout principles: http://www.alistapart.com/articles/responsive-web-design/