如何在相对布局背景中设置位图图像

Vis*_*ant 0 android xamarin

我从网址下载了一个位图,现在我希望将其设置为我的相对布局的背景.这是我的代码

Bitmap bitmap = null;
     WebClient client = new WebClient ();
     client.DownloadDataAsync (new Uri (mItems [position].Profile_Pic));
     client.DownloadDataCompleted += (se, res) => {
      bitmap = BitmapFactory.DecodeByteArray (res.Result, 0, res.Result.Length);
      var relativelayout=row.FindViewById<RelativeLayout>(Resource.Id.relativeLayout1);
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?感谢您的帮助

小智 7

你应该用 BitmapDrawable

var bitmapDrawable = new BitmapDrawable(bitmap);

...

relativelayout.SetBackground(bitmapDrawable);
//or
relativelayout.SetBackgroundDrawable(bitmapDrawable);
//SetBackgroundDrawable deprecated in API level 16
Run Code Online (Sandbox Code Playgroud)