私はこのgifライブラリを使っていますhttps://github.com/koral--/android-gif-drawable xmlにgifを表示するにはgifを表示し、ビューとしてはgifImageViewを表示するために、私はvolleyのImageRequestを使ってURLからgifをダウンロードしていました。 gifはアプリ内に静止画として表示されます。何が起こったのか理解できませんか?plsは私のコードを教えてくれます。あるいは、plsはボレを介してgifをダウンロードする方法を教えてくれます。定義されたボレーを使ってアンドロイドに.gifをダウンロードして読み込む方法は?
変数: -
SwipeDeck cardSwipe;
String url = "";
ImageView iv;
RequestQueue que;
RequestQueue que2;
SwipeCardAdapter adapter;
ArrayList<Bitmap> urls = new ArrayList<>();
これはJSON
public StringRequest strReq(){
StringRequest stringRequest = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray dataObject = jsonObject.getJSONArray("data");
for(int i = 0 ; i < dataObject.length() ; i++){
JSONObject thisObject = dataObject.getJSONObject(i);
JSONObject image = thisObject.getJSONObject("images");
JSONObject imageType = image.getJSONObject("original");
String imageUrl = imageType.getString("url");
Log.d("TAG", imageUrl);
URL url = new URL(imageUrl);
que2.add(imageReq(imageUrl));
}
} catch (JSONException e) {
e.printStackTrace();
Log.d("TAG","error occured in try and catch");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error.getCause() != null){
error.getCause().printStackTrace();
}
if(error.networkResponse != null){
Toast.makeText(MainActivity.this, "Network Response is " + error.networkResponse , Toast.LENGTH_SHORT).show();
}
}
});
return stringRequest;
}
をフェッチするstringRequest機能ブロックであり、これはURLからGIFをダウンロードするimageRequest機能ブロックである: -
public ImageRequest imageReq(String url){
ImageRequest imageRequest = new ImageRequest(url, new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap response) {
urls.add(response);
adapter.notifyDataSetChanged();
}
}, 0, 0, null, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(error.getCause() != null){
error.getCause().printStackTrace();
}
if(error.networkResponse != null){
Toast.makeText(MainActivity.this, "Network Response is " + error.networkResponse , Toast.LENGTH_SHORT).show();
}
}
});
return imageRequest;
}
これはgifImageViewを設定するアダプタクラスの内部です: -
GifImageView gifImageView = (GifImageView) convertView.findViewById(R.id.gifIV);
Bitmap thisGif = getItem(position);
gifImageView.setImageBitmap(thisGif);
GlideDrawableImageViewTargetを使用していただきありがとうございます。 –
さらに、サンプルを読み込んだらグライドをかなり丈夫に伸ばすことができます。DiskCacheStrategyを開始するには、 – dominicd
を参照してください。かなり良いですが、読み込み中の画面を表示するためにプレースホルダーを使用しましたが、私は間違いなくDiskCacheStrategyを見て、それを私のアプリに適用します。もう一度おねがいします。 –