[英]Volley NetworkImageView
我有一個GridView,其中圖像由Volley Library從Network中獲取。 當我單擊一個項目時,下載后圖像將以全屏全分辨率打開,這需要一些時間。 所以我用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中的Next on Image活動是與已經加載到網格View中的Network Image(thumbnail)相同,因此它可能很快。
因此,我要問的是顯示在下一個Activity的NetworkImageView中從gridView中選擇的同一圖像。
您將必須對圖像進行緩存以重新使用它們。 請仔細閱讀本傑克為鏈接中的緩存提供了一個漂亮的解決方案。 希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.