Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Background as null

Tags:

android

If I use the following line in the xml layout:

android:background="@null"
  1. Is it safe?
  2. Is effective from a performance point of view? Or it's better to set the layout's or the component's bacground from the actual code as null?
like image 936
Nick Robertson Avatar asked Jan 04 '13 10:01

Nick Robertson


1 Answers

  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.

  2. 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.

like image 115
Farooq Avatar answered Oct 05 '22 06:10

Farooq