【发布时间】:2016-01-20 11:36:01
【问题描述】:
我是 Android 的绝对初学者。现在我开始使用 volley 进行 Http 请求和图像缓存。所以从这个链接下载 volley.jar - http://api.androidhive.info/volley/volley.jar 。然后我把它放在 libs 库中。然后我按照教程创建了一个缓存类。
我的图片缓存类
package com.example.newfeeds.volley;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
但它一直说无法在导入命名空间中解析符号 ImageLoader。
我的项目结构截图如下。
我正在学习本教程。 http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/
【问题讨论】:
-
可能是
jar文件的问题。尝试通过Gradle' instead of jarcompilecom.mcxiaoke.volley:library:1.0.19'添加截击 -
它现在正在工作。我刚刚关闭了 Android Studio 并再次打开它。它是如此有线。
标签: java android android-volley