MvxGridView very slow on scrolling

Hi guys I'm using MvxGridView to display images in 4 columns. It has really bad perfomance on scrolling. Is it any way to fix it?

My MainView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxGridView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:numColumns="4"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="5dp"        
    android:gravity="center"
    android:stretchMode="columnWidth"
    local:MvxBind="ItemsSource Images"
    local:MvxItemTemplate="@layout/image_item" />

image_item:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    local:MvxBind="Bitmap ImageData,Converter=InMemoryImage" />
 </LinearLayout>

MainViewModel:

public class MainViewModel : MvxViewModel
{   
    public MainViewModel(IImageService imageUrlGetter)
    {            
        Images = _imageUrlGetter.GetImageViewModels().ToList();
    }

    private List<ImageItemViewModel> _images;
    public List<ImageItemViewModel> Images
    {
        get { return _images; }
        set
        {
            _images = value;
            RaisePropertyChanged(() => Images);
        }
    }
}

_imageUrlGetter returns constant List.

ImageItemViewModel:

public class ImageItemViewModel : MvxViewModel
{
    private IImageDownloaderService _imageDownloaderService;                  

    public ImageItemViewModel(IImageDownloaderService imageDownloaderService, string imageUrl)
    {
          _imageDownloaderService = imageDownloaderService;
          _imageDownloaderService.DownloadImageCompleted += ImageDownloaded;            
          _imageDownloaderService.StartDownloadImageFromWeb(imageUrl);
    }

    private byte[] _imageData;
    public byte[] ImageData
    {
        get
        {
            return _imageData;
        }

        set
        {
            SetProperty(ref _imageData, value);
        }
    }

    private void ImageDownloaded(object sender, DownloadCompletedEventHandlerArgs args)
    {
        ImageData = args.ResultStream.ToArray();
    }
}  

Answers

  • DK90DK90 USMember ✭✭✭

    @Ivan1111 With the above code i won't know whether the Download is happening in a background thread or service; May be the slow scrolling could be because of loading all the images in one shot or the List population is done in Main Thread. There is an article about using MvxGridView & MvxImageview as an itemstemplate, you can read it from here. If that doesn't help give more info about the code.

  • Its_me_ManuIts_me_Manu CAMember

    @Ivan1111 : Did you get this working? I am trying to implement MvxGridView but having a hard time because there are not much resources on it. If you made it work then please give me some tips on how I implement this. I also posted a question about the same in stackoverfolow (How to bind images to gridview in MvvmCross)

Sign In or Register to comment.