프로그래밍/Android

Fresco 이미지 wrap_content로 로딩하는 법

Lou Park 2019. 3. 10. 19:16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    ImageRequest request = ImageRequestBuilder
                .newBuilderWithSource(Uri.parse(jjalUrl))
                .build();
 
    ivImage.setController(Fresco.newDraweeControllerBuilder()
                .setOldController(ivImage.getController())
                .setLowResImageRequest(request)
                .setAutoPlayAnimations(true)
                .setControllerListener(new BaseControllerListener() {
                    @Override
                    public void onIntermediateImageSet(String id, @Nullable Object imageInfo) {
                        super.onIntermediateImageSet(id, imageInfo);
                        updateViewSize(ivImage, (ImageInfo) imageInfo);
                    }
 
                    @Override
                    public void onFinalImageSet(String id, @Nullable Object imageInfo, @Nullable Animatable animatable) {
                        super.onFinalImageSet(id, imageInfo, animatable);
                        updateViewSize(ivImage, (ImageInfo) imageInfo);
                    }
                })
                .build());
 
 
    void updateViewSize(SimpleDraweeView view, @Nullable ImageInfo imageInfo) {
        if (imageInfo != null) {
            view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            view.setAspectRatio((float) imageInfo.getWidth() / imageInfo.getHeight());
        }
    }
                    
cs