我有一个GridView,其中的图像是由Volley库从网络中获取的。当我点击一个项目时,图片会在下载后以全屏全屏打开,这需要一些时间。所以我用AppBar更改了它,但我仍然使用相同的方法来显示它,这同样需要同样的时间。
这就是:
private void fetchFullResolutionImage() {
String url = selectedPhoto.getPhotoJson();
// volley's json obj request
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url,
(String)null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG,
"Image full resolution json: "
+ response.toString());
try {
// Parsing the json response
JSONObject entry = response
.getJSONObject(TAG_ENTRY);
JSONArray mediacontentArry = entry.getJSONObject(
TAG_MEDIA_GROUP).getJSONArray(
TAG_MEDIA_CONTENT);
JSONObject mediaObj = (JSONObject) mediacontentArry
.get(0);
String fullResolutionUrl = mediaObj
.getString(TAG_IMG_URL);
// image full resolution widht and height
final int width = mediaObj.getInt(TAG_IMG_WIDTH);
final int height = mediaObj.getInt(TAG_IMG_HEIGHT);
Log.d(TAG, "Full resolution image. url: "
+ fullResolutionUrl + ", w: " + width
+ ", h: " + height);
ImageLoader imageLoader = AppController
.getInstance().getImageLoader();
// We download image into ImageView instead of
// NetworkImageView to have callback methods
// Currently NetworkImageView doesn't have callback
// methods
imageLoader.get(fullResolutionUrl,
new ImageLoader.ImageListener() {
@Override
public void onErrorResponse(
VolleyError arg0) {
Toast.makeText(
getApplicationContext(),
getString(R.string.msg_wall_fetch_error),
Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(
ImageLoader.ImageContainer response,
boolean arg1) {
if (response.getBitmap() != null) {
// load bitmap into imageview
backdrop
.setImageBitmap(response
.getBitmap());
}
}
});
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getString(R.string.msg_unknown_error),
Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
// unable to fetch wallpapers
// either google username is wrong or
// devices doesn't have internet connection
Toast.makeText(getApplicationContext(),
getString(R.string.msg_wall_fetch_error),
Toast.LENGTH_LONG).show();
}
});
// Remove the url from cache
AppController.getInstance().getRequestQueue().getCache().remove(url);
// Disable the cache for this url, so that it always fetches updated
// json
jsonObjReq.setShouldCache(false);
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq);
}所以我在想的可能是,我可以在下一个活动中显示图像,这是在AppBar中,将是相同的网络图像(缩略图),它已经加载到网格视图中,所以它可能会更快。
因此,我所要求的是在下一个活动的NetworkImageView中显示从gridView中选择的相同图像。
发布于 2016-02-13 22:12:25
您必须对图像进行缓存才能重用它们。请通过this杰克给出了一个在链接中缓存的漂亮解决方案。希望能有所帮助。
https://stackoverflow.com/questions/35380045
复制相似问题