所以我一直试图让它异步下载images.my app运行缓慢,滞后和延迟
public override View GetView(int position, View convertView,ViewGroup parent)
{
View view = convertView ?? _inflater.Inflate (Resource.Layout.textViewItems, parent, false);
if (track.artwork_url != null) {
var imageBitmap = GetImageBitmapFromUrl(track.artwork_url);
if (imageBitmap != null && imageBitmap.Length > 0) {
var converterImage = BitmapFactory.DecodeByteArray (imageBitmap, 0, imageBitmap.Length);
viewHolder.Image.SetImageBitmap(converterImage);
}
} else {
viewHolder.Image.SetImageResource(Resource.Drawable.img1);
}
return view;
}
public static byte[] GetImageBitmapFromUrl(string url)
{
byte [] imageBitmap = null;
using (var webClient = new WebClient())
{
var imageBytes = webClient.DownloadData(url);
imageBitmap = imageBytes;
}
return imageBitmap;
}
所有图像都以listview(100px高度和宽度)加载。我也设置了ImageView.layout_width = 70dp和高度。 但我不能在列表视图中向下或向上滚动。因为listview变得如此滞后和非常糟糕
我认为问题在于GetImageBitmapFromUrl。如何解决。
答案 0 :(得分:1)
您可以使用MonoDroid.UrlImageViewHelper异步加载图片。
if (track.artwork_url != null) {
viewHolder.Image.SetUrlDrawable(track.artwork_url, Resource.Drawable.img1);
}
您可以在Xamarin论坛上查看更多详细信息:ListView - Asynchronous Image Loading (from URL)