What’s the difference between setting background image in layout xml and setting it from the code? Does setting image from code use more memory?
For example:
In XML:
<ImageView android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_img" />
From the code:
((ImageView)findViewById(R.id.background)).setBackgroundResource(R.drawable.background_img);
Thanks.
Off the top of my head, I can only think of it in terms of optimization.
Setting in the layout means that the background is already there during the setContentView, you don’t need the extra steps to set it in your code.
If you don’t have to customize it, it would be faster to leave in the XML.