通过xml直接加载drawable是否效率低下?

时间:2018-04-28 13:24:16

标签: android android-drawable

实际上我在drawables中制作了一个渐变,然后通过xml将其加载到背景中。所以我要问的是这样做是一个好习惯,如果不是,那么如何以编程方式有效地将位图加载到背景中?

顺便说一下,它是mainScreen的布局。

XML

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:background="@drawable/gradient"**
android:fitsSystemWindows="true"
/>

1 个答案:

答案 0 :(得分:0)

是的,它同样有效。

项目编译后没有太大区别,使用XML实现这一点的好处包括节省时间和避免编码错误(有很多错误的方法以编程方式完成)。

此外,除非你做了很多次(比如在1个视图中对布局进行100次或1000次充气),即使很小的性能差异也可以忽略不计。