Android:使用 Picasso 在 horizo​​ntalscrollview 中延迟加载图像

标签 android horizontalscrollview picasso android-lazyloading

我正在尝试使用 Picasso 实现水平 ScrollView 以实现延迟加载。 ImageView 添加到 Scrollview 但未加载图像。

请帮忙!!

我的代码是

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

我的xml是

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

最佳答案

您是否更改了图像的正确路径?看起来它将加载类似 http://www.example.com/category_accomodation_1 的内容这对我来说看起来不像是有效的图片 URL。

关于Android:使用 Picasso 在 horizo​​ntalscrollview 中延迟加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22990142/

相关文章:

没有身份验证的 Android SyncAdapter 与 Android 服务

java - picasso 图像未在 Gridview Android 中加载

android - 导航架构组件 - 无法从 onResume 导航到 fragment

java - 如何获取android主类的实例?

android - 如何使用数据绑定(bind)调用静态方法?

android - 水平滚动时展开和折叠动画

android - 填充时刷新布局

ios - 向水平分页UIScrollView添加图片

android - displayImage 和 loadImage 缓存的不是同一个文件?

android Picasso 从存储中加载图像