将背景设置为空 [英] Set Background as null

查看:98
本文介绍了将背景设置为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在xml布局中使用以下行:

If I use the following line in the xml layout:

android:background="@null"

  1. 安全吗?
  2. 从性能角度来看有效吗?或者最好从设置布局或组件的背景实际代码为空吗?

推荐答案

  1. android:background ="@ null" 是绝对安全的.如果您想根据代码中的逻辑设置背景,则可以使用此方法.如果您未在代码中设置背景,则背景仍将保持不变,绝不会造成任何问题.

  1. android:background="@null" is absolutely safe. If you want to set the background based on your logic in code, you can definitely use this; and if you do not set the background in code, it is still the same and will never cause any problems.

从性能的角度来看,您应该通过XML而不是通过编程方式加载背景,因为您的布局仅会从XML加载一次.如果您根据逻辑在代码中进行设置,则可能会加载多次.但是,无论哪种情况,性能都几乎相同,差异不大.您应该从逻辑的角度决定使用哪种方法(如果您永远不会改变背景,请使用XML方法).重点是,使用适当大小的图像作为背景.那将在性能上产生真正的差异.两种方法中的大图像加载都将花费更多时间.

From a performance point of view, you should load the background via XML instead of programmatically because your layout will be loaded only once from the XML. If you set it in code based on your logic, it may be loaded more than once. However, in either case, the performance is almost the same, not a big difference. You should decide which approach to use from your logic point of view (if you will never change the background, use the XML approach). The point is, use the image of the appropriate size as the background. That will make the real difference in performance. Big images will take more time to load in either approach.

这篇关于将背景设置为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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