2017-03-14 1 views
0

여기에 뭔가 잘못입니까? 그레이를 자리 표시 자로로드하려고하지만로드하지 않습니다. 이미 다른 이미지 세트가 있거나로드 된 경우에만 발생하는 것으로 보입니다.ColorDrawable 자리 표시자가 글라이딩에로드되지 않습니다.

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(); 
     } 
    }); 

답변

2

아래 코드를 사용해보십시오 :

글라이드 버전 : '글라이드 : com.github.bumptech.glide를 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> 

유효한 URL과 잘못된를 사용해보십시오 유효한 URL의 경우 이미지로드 전에 회색 색상이 표시되고 잘못된 URL의 경우 회색 자리 표시자가 나타납니다.

관련 문제