Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在android中使用match parent获取毕加索的最佳实践_Android_Android Recyclerview_Picasso_Prefetch - Fatal编程技术网

在android中使用match parent获取毕加索的最佳实践

在android中使用match parent获取毕加索的最佳实践,android,android-recyclerview,picasso,prefetch,Android,Android Recyclerview,Picasso,Prefetch,我正在使用毕加索下载图片并在回收视图中显示它们。我试图防止在滚动RecyclerView和毕加索下载新图片时发生的小延迟,所以我使用fetch。当我对图片使用精确大小时,效果很好,但现在我在xml中使用“匹配父项”(在所有设备上工作),从那时起就有一个延迟,当我来回滚动时,它不记得图片(已经看到的图片上的延迟)。 我尝试了just fit()和centerCrop(),但速度很慢,因此这是我目前解决此问题的尝试: 在适配器中(只运行一次),我设置了一个侦听器来获取ImageView的确切大小 p

我正在使用毕加索下载图片并在回收视图中显示它们。我试图防止在滚动RecyclerView和毕加索下载新图片时发生的小延迟,所以我使用fetch。当我对图片使用精确大小时,效果很好,但现在我在xml中使用“匹配父项”(在所有设备上工作),从那时起就有一个延迟,当我来回滚动时,它不记得图片(已经看到的图片上的延迟)。 我尝试了just fit()和centerCrop(),但速度很慢,因此这是我目前解决此问题的尝试:

在适配器中(只运行一次),我设置了一个侦听器来获取ImageView的确切大小

private void preloadImage(final View picture) {
    ViewTreeObserver observer = picture.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            PictureUtil.fetchImage(picture.getHeight(), picture.getWidth());
            ViewTreeObserver mObserver = picture.getViewTreeObserver();
            mObserver.removeOnGlobalLayoutListener(this);
        }
    });
}
在PictureUtil中,我获取所有图片:

   public static void fetchImage(int height, int width) {
    if (height > 0 && width > 0) {
        for (House house : Houses.houseList) {
            Picasso.get().load(getFrontPicturePath(house.id))
                    .resize(width, height)
                    .centerCrop()
                    .fetch();
        }
    }
}
在适配器中,我也是这样加载它们的:

Picasso.get()
            .load(PictureUtil.getFrontPicturePath(houseId))
            .error(PictureUtil.getPlaceholderPath(context))
            .fit()
            .centerCrop()
            .into(view);
这是xml中的imageview:

        <ImageView
            android:id="@+id/house_row_picture"
            android:layout_width="match_parent"
            android:layout_height="170dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:src="@drawable/img_small" />

所以问题又来了,我在图像上得到了延迟(不像我有固定大小的时候),当我在循环视图中滚动时,图像消失并再次加载。我做错了什么?这方面有最佳实践吗


提前感谢

据我所知,毕加索在缓存中只存储了很短的时间。如果我是,请纠正我wrong@AndroidAnton你是对的,但当我使用固定大小时,它没有重新加载图片,所以我想问题应该在其他地方。据我所知,毕加索只在缓存中存储了很短的时间。如果我是,请纠正我wrong@AndroidAnton你是对的,但是当我使用固定大小时,它没有重新加载图片,所以我想问题应该在别处。