莫不是在XML或Java文件写入同一code(用于布局)之间的性能差异?是在、布局、差异、性能

2023-09-07 00:31:14 作者:雪凝固了记忆

我知道,有什么你可以和不可以在XML和Java文件做差异,但到目前为止,我明白了一个java文件可以竭尽所能,一个XML文件可以做的,至少这是书上写的我正在读(见下文引号)。

我的问题是,如果为此中可以有使用Java语言编写或XML的code性能差异,如果它是:这两个是有利的比其他? 这不是一个关于正确的方式做这个问题,这是一个关于纯粹的性能问题。

我知道XML code被编译成Java code,也许这是可以做到比翻译的java code更有效,因为它会更容易编写XML比Java文件编译? (基于XML确实很容易解析,因为它例如更连贯,结构简单的假设)

的引用这本书的

这是其中规定,一个java文件可以做一切的XML文件可以做这本书实际报价。它首先解释说,有两种方法可以使用​​户界面,即在一个声明和编程方式这样做:

  

该声明的方法包括使用XML声明什么UI  看起来像,...

    

...

    安卓开发学习周第五篇 工程相关解析

一个程序的用户界面包括编写Java code开发的用户界面。

    

...

    

您可以声明所做的一切,你也可以做编程的。

解决方案

在您的活动类手工创建UI层次结构会更快,但 MUCH 超过使用关于LayoutInflater XML布局文件(复杂性能看充气布局时所使用的 CreateView的(字符串名称,字符串preFIX,AttributeSet中的ATTRS)方法,你会发现它不是一个速度守护进程),我不能让您在任何%,虽然数字

I know that there are differences in what you can and can not do in XML and a java file, but so far I understood that a java file can do everything a XML file can do, at least that's written in the book I am reading (see the quotes below).

My question is therefor if there can be a performance difference in writing your code in java or xml, and if it is: which of the two is favored over the other? This is not a question about the correct way to do this, it's a question about pure performance.

I know that the xml code is compiled into java code, maybe this can be done more efficient than translating java code since it would be easier to write a compiler for xml than for java files? (based on the assumption that indeed xml is easier to parse since it's for example more coherent and the structure is simpler)

Quote from the book

This is the actual quote from the book which states that a java file can do everything an xml file can do. It does so by first explaining that there are two ways to make User Interfaces, namely in a Declarative and Programmatic way:

The declarative approach involves using XML to declare what the UI will look like, ...

...

A programmatic user interface involves writing Java code to develop the UI.

...

Everything you can do declaratively, you can also do programmatically.

解决方案

creating the ui hierarchy by hand in your activity class will be faster but MUCH more complicated than using xml layout files (about the LayoutInflater performance see its createView(String name, String prefix, AttributeSet attrs) method used when inflating the layouts and you will find out its not a speed daemon), i cannot give you any numbers in % though

 
精彩推荐
图片推荐