Android 保存图像的实例列表在RecycleView中显示它们

Android 保存图像的实例列表在RecycleView中显示它们,android,android-fragments,tabs,Android,Android Fragments,Tabs,我的应用程序中的第一个活动有三个选项卡第一个选项卡包括包含图像列表的回收视图,这些图像来自webservice当单击第二个或第三个选项卡,然后再次单击第一个选项卡从webservice加载图像我想先为片段保存实例,在回收器视图的适配器中,使用库显示图像。它有现成的图像缓存。当您第一次下载图像时,它将缓存在您的设备上。当您再次尝试下载具有相同URL的图像时(当您从第三个选项卡返回时),毕加索将显示缓存中的图像,并且不会再次下载 其次,您可以将图像列表保存在片段中。在你的片段覆盖中 Strin

我的应用程序中的第一个活动有三个选项卡第一个选项卡包括包含图像列表的回收视图,这些图像来自webservice当单击第二个或第三个选项卡,然后再次单击第一个选项卡从webservice加载图像我想先为片段保存实例,在回收器视图的适配器中,使用库显示图像。它有现成的图像缓存。当您第一次下载图像时,它将缓存在您的设备上。当您再次尝试下载具有相同URL的图像时(当您从第三个选项卡返回时),毕加索将显示缓存中的图像,并且不会再次下载

其次,您可以将图像列表保存在片段中。在你的片段覆盖中

   String BUNDLE_IMAGES = "imgs";

    @Override 
    public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            ourState.putStringArrayList(BUNDLE_IMAGES , getImageArray()) 
    }

    private List<String> getImageArray(){
         //your implementation to get image array
    }
String BUNDLE\u IMAGES=“imgs”;
@凌驾
SaveInstanceState上的公共无效(束超出状态){
super.onSaveInstanceState(超出状态);
putStringArrayList(BUNDLE\u IMAGES,getImageArray())
}
私有列表getImageArray(){
//获取图像数组的实现
}
恢复

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        List<String> images =savedInstanceState.getStringArrayList(BUNDLE_IMAGES);
    }
}
@覆盖
已创建ActivityState上的公共无效(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
如果(savedInstanceState!=null){
List images=savedInstanceState.getStringArrayList(BUNDLE_images);
}
}
有关保存/还原碎片状态的详细信息:

更新:使用图像缓存:

private LruCache<String, Bitmap> mMemoryCache;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    // Get max available VM memory, exceeding this amount will throw an
    // OutOfMemory exception. Stored in kilobytes as LruCache takes an
    // int in its constructor.
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;

    mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than
            // number of items.
            return bitmap.getByteCount() / 1024;
        }
    };
    ...
}

public void addBitmapToMemoryCache(String key, Bitmap bitmap) {
    if (getBitmapFromMemCache(key) == null) {
        mMemoryCache.put(key, bitmap);
    }
}

public Bitmap getBitmapFromMemCache(String key) {
    return mMemoryCache.get(key);
}
私有LruCache-mMemoryCache;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
...
//获取最大可用VM内存,超过此数量将抛出
//OutOfMemory异常。在LruCache接受
//int在其构造函数中。
final int maxMemory=(int)(Runtime.getRuntime().maxMemory()/1024);
//将可用内存的1/8用于此内存缓存。
最终int cacheSize=maxMemory/8;
mMemoryCache=新的LruCache(缓存大小){
@凌驾
受保护的int-sizeOf(字符串键、位图){
//缓存大小将以KB为单位,而不是以字节为单位
//项目数量。
返回bitmap.getByteCount()/1024;
}
};
...
}
public void addBitmapToMemoryCache(字符串键、位图){
if(getBitmapFromMemCache(key)==null){
mMemoryCache.put(键,位图);
}
}
公共位图getBitmapFromMemCache(字符串键){
返回mMemoryCache.get(key);
}

首先,我正在使用(AWS)Amazon Web服务,下载图像时不使用URL。下载后,您能帮我制作缓存图像,而不使用Picasso@HellCat2405吗