Android: Setting Background Image for RelativeLayout?

前端 未结 4 1514
耶瑟儿~
耶瑟儿~ 2021-01-04 04:31

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

4条回答
  •  情话喂你
    2021-01-04 05:09

    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);
    

提交回复
热议问题