Android的XML VS Java的布局表现 [英] Android xml vs java layouts performance

查看:234
本文介绍了Android的XML VS Java的布局表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android SDK中提供了开发人员编写的XML文件或者直接在java中code布局。我看了一下它,大家都说XML更易于维护和simplyer写的,但它们是静态的。否则Java布局是动态的,但没有人评论性能问题。只有一件事,我发现有关性能进行了嵌套布局有业绩产生负面影响。写嵌套布局,而不是它是更好地使自定义的。到目前为止好。)

Android SDK offers to developers to write layouts in xml files or directly in java code. I have read about it and everyone says that xml are easier to maintain and simplyer to write, but they are static. Otherwise java layout are dynamic, but no one comments performance issues. The only one thing which I found about performance was nesting layout have negative impact of performance. Instead of writing nested layout it's better to make custom one. So far so good ;).

怎么样的布局设计? XML或Java code?如何是XML文件解析我的Andr​​oid,在运行时或编译时?即使他们被解析在编译时,他们应该在运行时使用。因此,这将是更快申报RelativeLayout的XML或在onCreate方法声明它?

What about layout design? xml or java code? How are xml files parsed my android, at runtime or compile time? Even if they are parsed at compile time, they should be used in runtime. So which will be faster to declare RelativeLayout in xml or to declare it in onCreate method?

推荐答案

一个布局,定义了视觉结构的用户界面,如用户界面的活动或应用程序部件。您可以通过两种方式申报的布局:

A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. You can declare a layout in two ways:

  • 声明的UI元素在XML 。 Android提供了一个简单的XML 词汇相对应的视图类和子类,例如 为那些部件和布局。

  • Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts.

实例化布局元素在运行时。您的应用程序可以创建 查看和ViewGroup中的对象(和操纵它们的属性) 编程。

Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

Android框架为您提供了用于申报和管理应用程序的用户界面的这些方法之一或两者的灵活性。例如,你可以声明在XML应用程序的默认布局,包括出现在他们和他们的属性屏幕元素。然后,您可以添加code。在您的应用程序会修改屏幕对象的状态,包括那些在XML中声明,在运行时。

The Android framework gives you the flexibility to use either or both of these methods for declaring and managing your application's UI. For example, you could declare your application's default layouts in XML, including the screen elements that will appear in them and their properties. You could then add code in your application that would modify the state of the screen objects, including those declared in XML, at run time.

ADT插件为Eclipse提供的XML的布局preVIEW - 用XML文件打开,选择版式选项卡

The ADT Plugin for Eclipse offers a layout preview of your XML — with the XML file opened, select the Layout tab.

您也应该尝试的层次结构查看器工具,用于调试布局 - 它揭示布局属性值,绘制线框与填充/保证金的指标,并充分渲染视图,而你调试仿真器或设备

You should also try the Hierarchy Viewer tool, for debugging layouts — it reveals layout property values, draws wireframes with padding/margin indicators, and full rendered views while you debug on the emulator or device.

该layoutopt工具可以让你快速分析您的布局和层次结构的低效率和其他问题。

The layoutopt tool lets you quickly analyze your layouts and hierarchies for inefficiencies or other problems.

    The advantage to declaring your UI in XML is that it enables you to better separate the 
presentation of your application from the code that controls its behavior. Your UI descriptions are
external to your application code, which means that you can modify or adapt it without having to
modify your source code and recompile. For example, you can create XML layouts for different screen
orientations, different device screen sizes, and different languages. Additionally, declaring the
layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug 
problems. 

当您编译应用程序时,每个XML布局文件被编译成一个View资源。你应该从你的应用程序code加载布局资源,在你的 Activity.onCreate()的回调实现。通过调用这么做的setContentView(),它传递的参考布局资源的形式为:

When you compile your application, each XML layout file is compiled into a View resource. You should load the layout resource from your application code, in your Activity.onCreate() callback implementation. Do so by calling setContentView(), passing it the reference to your layout resource in the form of:

我觉得它太简单,只是访问此链接<一个href="http://developer.android.com/guide/topics/ui/declaring-layout.html">http://developer.android.com/guide/topics/ui/declaring-layout.html并获得更多的信息。

I think its too much just visit this link http://developer.android.com/guide/topics/ui/declaring-layout.html and get more information..

这篇关于Android的XML VS Java的布局表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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