我应该膨胀的布局或以编程方式创建它吗? [英] Should I inflate a layout or programmatically create it?

查看:131
本文介绍了我应该膨胀的布局或以编程方式创建它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Android的程序,

这个问题已经困扰了我一段时间,我应该夸大布局尽可能或者我应该编程方式创建布局尽可能?

如果我们把便民放在一边,这是更好?快点?更安全? 任何具体的投入是很大的AP preciated。

问候,

解决方案
  

我看,所以膨胀是谷歌/ Android的建议和做布局的常规方式

是的。

  

和它不通过多减慢应用的运行时

有不通过多减缓该应用程序的运行时的相比,做同样的在Java中工作自己

  

由于我读的地方在Android的开发者网站,这是一个缓慢的过程,意见应该是再利用尽可能多地诉诸夸大了。

回收的观点在适配器视图 - 您已经阅读这个建议最有可能的地方 - 是很重要的,因为回收的观点比的更快的创建的意见的无论怎样这些观点创建的。同样,比较不是通货膨胀之间与滚动自己的Java code,但通货膨胀和没有创造新的意见的。

之间
  

我应该夸大布局尽可能或者我应该编程方式创建布局尽可能?

充气,请。

  

哪个好?

通胀考虑到资源集(根据屏幕大小和方向,例如,不同的布局)。通货膨胀考虑到款式账户覆盖。通货膨胀的作品更好地与工具。

  

更快?

有可能是一些场景,硬codeD Java是比通货膨胀快,就像有一些场景中,硬codeD汇编语言比C快在大多数情况下,速度差没有足够重要,值得的麻烦。

  

更安全?

我不知道你认为安全是什么在这方面的意思。

Regarding Android programming,

This question has been bothering me for a while, should I inflate layout as much as possible or should I programmatically create the layouts as much as possible?

If we put "convenience" aside which is better? faster? safer? Any concrete inputs are greatly appreciated.

Regards,

解决方案

I see, so inflating is the Google/Android recommended and conventional way of doing layouts

Yes.

and it doesn't slow down the runtime of the application by much

It doesn't slow down the runtime of the application by much when compared to doing the same work yourself in Java.

Because I read somewhere on the developer site of Android that it is a slow process and views should be "reused" as much as possible before resorting to inflating.

Recycling views in an AdapterView -- the most likely place for you to have read that advice -- is important, because recycling views is faster than creating views, no matter how those views are created. Again, the comparison is not between inflation versus rolling your own Java code, but between inflation and not creating new views.

should I inflate layout as much as possible or should I programmatically create the layouts as much as possible?

Inflate, please.

which is better?

Inflation takes into account resource sets (e.g., different layouts based on screen size and orientation). Inflation takes into account overrides of styles. Inflation works better with tooling.

faster?

There are probably some scenarios where hard-coded Java is faster than inflation, just as there are some scenarios in which hard-coded assembly language is faster than C. In most cases, the speed difference is not important enough to warrant the hassle.

safer?

I do not know what you consider "safe" to mean in this context.

这篇关于我应该膨胀的布局或以编程方式创建它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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