美文网首页
Fresco 同一URI,重新加载图片

Fresco 同一URI,重新加载图片

作者: eveo | 来源:发表于2016-04-22 15:59 被阅读1012次
    需求
        在DraweeView加载图片失败的时候显示同一个布局上的按钮,点击按钮可让DraweeView重新加载。
    
    问题,失败的时候显示了按钮,但是点击了按钮后就没有了反应,代码如下:
    private void showDraweeView(PhotoDraweeView view, String url) {  
     Uri uri = Uri.parse(url);   
     if (null == uri) { return;  }  
     ControllerListener listener = new BaseControllerListener<ImageInfo>() {    
    
      public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {     
       super.onFinalImageSet(id, imageInfo, animatable);    
        if (imageInfo == null || mPhotoView == null) { return;  }              
        mPhotoView.update(imageInfo.getWidth(), imageInfo.getHeight());    
    }      
     public void onFailure(String id, Throwable throwable) {        
        super.onFailure(id, throwable);   
         visibleButton(true);      
      }  
      };  
      DraweeController controller = Fresco.newDraweeControllerBuilder()
        .setUri(uri)          
        .setControllerListener(listener)       
        .setTapToRetryEnabled(true)        
        .build();   
      view.setController(controller); 
      GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())            
       .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)            
       .setProgressBarImage(new CustomProgressBar(mContext))       
       .build();  
        mPhotoView.setHierarchy(hierarchy);
    

    }

    修改后的代码
    private void showDraweeView(PhotoDraweeView view, String url) {   
     GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())            
         .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)             
         .setProgressBarImage(new CustomProgressBar(mContext))   
         .build();
         mPhotoView.setHierarchy(hierarchy);
     Uri uri = Uri.parse(url);  
     if (null == uri) { return; } 
       ControllerListener listener = new BaseControllerListener<ImageInfo>() { 
       public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { 
           super.onFinalImageSet(id, imageInfo, animatable); 
           if (imageInfo == null || mPhotoView == null) { return; }            
           mPhotoView.update(imageInfo.getWidth(), imageInfo.getHeight());} 
       public void onFailure(String id, Throwable throwable) {
            super.onFailure(id, throwable); 
           visibleReloadView(true);
        } 
     };
    DraweeController controller =  
    Fresco.newDraweeControllerBuilder()    
        .setUri(uri)   
         .setControllerListener(listener)            
         .setTapToRetryEnabled(true)   
         .build(); 
    view.setController(controller); 
    }
    
    其实就是setHierarchy(hierarchy)在setController(controller)的后面被调用

    相关文章

      网友评论

          本文标题:Fresco 同一URI,重新加载图片

          本文链接:https://www.haomeiwen.com/subject/mwrxrttx.html