Android: Setting Background Image for RelativeLayout?

Vivek picture Vivek · Feb 5, 2011 · Viewed 35.2k times · Source

I have downloaded an image at runtime. Now I want to set it as a background for RelativeLayout. Does it possible?

Answer

SteD picture SteD · Feb 5, 2011

Check out the setBackgroundDrawable, or maybe createFromPath in the Drawable class.

   RelativeLayout rLayout = (RelativeLayout) findViewById (R.id.rLayout);
   Resources res = getResources(); //resource handle
   Drawable drawable = res.getDrawable(R.drawable.newImage); //new Image that was added to the res folder

    rLayout.setBackground(drawable);