使用什么是更好地创建布局。 Java或XML? [英] What is better to use for creating layouts. Java or XML?

查看:128
本文介绍了使用什么是更好地创建布局。 Java或XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的安卓和我工作的一个新的应用程序。

I'm new to Android and am working on a new application.

我创建了 XML 文件,它恰好是相当大的一些布局。我知道,我可以节省大量的空间,如果我创造我的布局与的Java 循环,但另一方面布局的东西,我很可能不会需要很更改频繁。

I've created some layouts in the XML document which happens to be quite large. I know that I can save a lot of space if I create my layouts with Java loops, but on the other hand layout is something that I won't probably need to change very often.

什么是更好的性能明智? 的Java code或 XML 布局?

What is better performance wise? Java code or the XML layout?

推荐答案

大多数时候我preFER 布局XML资源文件,但根据不同的所需要的。

Most of the time I prefer layout XML resource files, but it varies according to the need.

  1. 一,资源集(例如, RES /布局陆/ 除了 RES /布局/ )允许您定义多个用户界面在不同的环境中使用。

  1. First, the resource sets (e.g., res/layout-land/ in addition to res/layout/) allow you to define multiple UIs to be used in different circumstances.

  • 布局的土地 - >风景

  • layout-land -> for landscape

布局端口 - >人像

布局-V15 - >的Andr​​oid版本> = 15

layout-v15 -> for android version >= 15

布局sw600dp - >为具有一定宽度的屏幕

layout-sw600dp -> for screens with a certain width

二,有一些工具可以帮助你成功地创建这些布局资源。 Eclipse中的拖放和拖放GUI构建是其中之一。

Second, there are tools that can help you create those layout resources successfully. drag-and-drop GUI building of Eclipse is one of them.

第三,它更趋于简洁,所以如果你输入这个东西的手,将XML会少打字。

Third, it tends to be more terse, so if you're typing this stuff by hand, the XML will be less typing.

在Java的code,你必须编译和放大器;运行code,看看如何布局的样子,而在XML(如果你使用的是Eclipse),你可以直接看到它与Eclipse提供的工具。

In Java code you have to compile & run the code to see how the layout looks like, while in XML (if you are using eclipse) you can see it directly with the tools that eclipse provides.

有关的一切静态我使用XML,因为它很容易找到你的项目的结构。

For everything static I use XML, because it is easy to find in the structure of your project.

但在某些情况下,你要创建动态布局,你有没有其他的选择,然后是使用Java code。做个聪明,在这一点,所以如果你需要添加一些意见指出,看起来是一样的做到这一点。

But in some cases, you want to create dynamic layouts and you have no other choice then to use Java Code. Be smart, in this, so if you have to add several Views that look the same do this

从我的角度来看, XML布局是好的,如果你想给的android   自动处理布局。这对于像   数据输入型应用程序(如银行业应用程序)。 Java的布局   将是需要用户界面的严格控制应用程序更好   (如愤怒的小鸟)

From my perspective, xml layouts are good if you want android to handle the layouts automatically. This would be for things like data-entry type applications (like banking applications). Java layouts would be better for applications that need tight control of the UI (like angry birds)

这篇关于使用什么是更好地创建布局。 Java或XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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