Facebook Fresco using wrap_content

前端 未结 5 718
日久生厌
日久生厌 2020-12-05 03:07

I got a bunch of drawables that I want to load using fresco, I want to use wrap_content size for those images, how can I do it in xml with fresco? Or if xml is

5条回答
  •  既然无缘
    2020-12-05 03:43

    invoke updateWrapSize in onFinalImageSet

    void updateWrapSize(@Nullable ImageInfo imageInfo) {
            if (imageInfo != null) {
                boolean wrapH = getLayoutParams().height == ViewGroup.LayoutParams.WRAP_CONTENT;
                boolean wrapW = getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT;
                if (wrapH || wrapW) {
                    if (wrapW && !wrapH) {
                        getLayoutParams().width = (int) (imageInfo.getWidth() * (float) getLayoutParams().height / imageInfo.getHeight());
                    } else if (wrapH && !wrapW) {
                        getLayoutParams().height = (int) (imageInfo.getHeight() * (float) getLayoutParams().width / imageInfo.getWidth());
                    } else {
                        getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
                        getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                    }
                    setAspectRatio((float) imageInfo.getWidth() / imageInfo.getHeight());
                }
            }
        }
    

提交回复
热议问题