2017-03-14 1 views
0

Est-ce que je fais quelque chose de mal ici? Je veux charger ce gris comme un espace réservé cependant, il ne charge pas. Cela semble se produire seulement s'il y avait déjà un autre jeu d'images ou chargé.Espace réservé ColorDrawable ne se chargeant pas dans la plané

Glide.with(getContext()) 
    .load(url) 
    .placeholder(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray))) 
    .error(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray))) 
    .dontAnimate() 
    .into(new SimpleTarget<GlideDrawable>() { 
     @Override 
     public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { 
     image.setImageDrawable(resource); 
     } 

     @Override 
     public void onLoadFailed(Exception e, Drawable errorDrawable) { 
     resetImageView(); 
     } 
    }); 

Répondre

2

Essayez le code ci-dessous:

version Glide: compilation 'com.github.bumptech.glide: vol plané: 3.6.1'

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="100dp" 
     android:layout_height="100dp"></ImageView> 
</RelativeLayout> 



ImageView imageView = (ImageView) findViewById(R.id.imageView); 
     Glide.with(this) 
       .load("http://matplotlib.org/_images/color_demo.png") 
       .placeholder(new ColorDrawable(ContextCompat.getColor(MainActivity.this, R.color.placeholder_gray))) 
       .error(new ColorDrawable(ContextCompat.getColor(MainActivity.this, R.color.placeholder_gray))) 
       .dontAnimate() 
       .into(imageView); 

<color name="placeholder_gray">#A9A9A9</color> 

Essayez d'utiliser une URL valide et invalide URL.Pour une URL valide, une couleur grise apparaît avant le chargement de l'image et, pour une URL non valide, un espace réservé gris apparaît.