Android:为RelativeLayout设置背景图片?

标签 android android-layout android-relativelayout

我在运行时下载了一张图片。现在我想将它设置为 RelativeLayout 的背景。可能吗?

最佳答案

查看 setBackgroundDrawable ,或者可能是 createFromPath在 Drawable 类中。

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

关于Android:为RelativeLayout设置背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4906422/

相关文章:

android - 如何删除Android Studio中的 "call requires permission which may.."错误

Android Recyclerview 多个onclick项目

android - 如何将 onClick 的 androidx 数据绑定(bind)到带参数的静态方法

android - 使布局可滚动

安卓布局问题

java - Android 应用相对布局,包含 2-3 个元素和一个底部按钮

android - 何时使用多个首选项文件?

android - 管理堆大小

android - 不幸的是应用程序已停止

java - 我没有收到自定义选项卡的图标