SimpleDraweeView not resizing after scaling image in fresco

 ̄綄美尐妖づ 提交于 2019-11-29 15:29:51
plamenko

I strongly recommend that you read the Fresco documentation. All of your questions here are already answered there.

Drawee view does not support ImageView attributes (adjustViewBounds, getImageMatrix, etc.). See the documentation.

Read about intrinsic dimensions, again, in the documentation here.

If you really need to dynamically resize your view, with all of the disadvantages that come with that, you can do that by using a controller listener as explained here.

Hope that helps and let me know should you have any more questions.

Edijae Crusar

In order to make simpledraweeview resize, this is what i implemented a ControllerListener and changed simpleDraweeView height as desired.

private void loadImage(Uri fileUri,final SimpleDraweeView simpeDraweeView) {

    GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(context.getResources());

    GenericDraweeHierarchy hierarchy = builder
            .setProgressBarImage(new CircleProgressBarDrawable())
            .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)
            .build();


    ImageRequest requestBuilder = ImageRequestBuilder.newBuilderWithSource(fileUri)
            .setProgressiveRenderingEnabled(true)
            .build();


    ControllerListener<ImageInfo> contollerListener = new BaseContollerListener<ImageInfo>() {

    public void onFinalImageSet(String id, ImageInfo imageinfo,Animatable animatable) {

        if(imageinfo != null) {
           updateViewSize(imageinfo)
         }
    }

    DraweeContoller contoller = Fresco.newDraweeContollerBuilder()
                 .setContollerListener(contollerListener)
                 .setImageRequest(requestBuilder)
                 .build();

    simpleDraweeView.setHierarchy(hierarchy);
    simpleDraweeView.setController(contoller);

}

private void updateViewSize(ImageInfo imageinfo){
 //this is my own implementation of changing simple-drawee-view height
 // you canhave yours using imageinfo.getHeight() or imageinfo.getWidth();
 simpleDraweeView.getLayoutParams().height = imageinfo.getHeight();

   // don't forget to call this method. thanks to @plamenko for reminding me.

   simpleDraweeView.requestLayout()
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!