Search code examples
androidhorizontalscrollviewpicassoandroid-lazyloading

Android: Lazy Loading Image in horizontalscrollview using Picasso


I'm trying to implement a horizontal scrollview with Picasso for lazyloading . ImageView adding to the Scrollview but image is not loading.

Please Help !!

My code is

private void populateImages(Picasso picasso) {
    String imageURL = "URL";
    String[] imageArray = new String[]     {"category_accomodation_1","category_gadget_1","categpory_essential_services_1","category_home_1"};
    myGallery = (LinearLayout)findViewById(R.id.gallerylayout);
    for(int i = 0 ;i<imageArray.length;i++){
    myGallery.addView(insertPhoto(imageURL+imageArray[i])); 
}

public View insertPhoto(String path){
    LinearLayout layout = new LinearLayout(getApplicationContext());
    layout.setGravity(Gravity.CENTER);
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    Picasso.with(this).load(path).placeholder(R.drawable.load).into(imageView);
    layout.addView(imageView);
    return layout;
}

my xml is

       <HorizontalScrollView 
            android:id="@+id/imagescrollview"
            android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_toLeftOf="@+id/uploadphoto"
                android:layout_below="@+id/recommend">
            <LinearLayout android:id="@+id/gallerylayout"
        android:layout_width="wrap_content"
        android:baselineAligned="false"
        android:orientation="horizontal"
        android:layout_height="50dp"> 
        </LinearLayout>
        </HorizontalScrollView>

Solution

  • Have you changed the path is correct to the images? It looks like it will be loading something like http://www.example.com/category_accomodation_1 which doesn't look like a valid image URL to me.