1. 程式人生 > >Fresco如何獲取圖片的真是寬高比例,實現瀑布流

Fresco如何獲取圖片的真是寬高比例,實現瀑布流

public class UitlsToos {

    /**
     * 通過imageWidth 的寬度,自動適應高度
* * @param simpleDraweeView view
     * * @param imagePath  Uri
     * * @param imageWidth width
     */
public static void setControllerListener(final SimpleDraweeView simpleDraweeView, String imagePath, final int imageWidth) {
        final 
ViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams(); ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() { @Override public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) { if
(imageInfo == null) { return; } int height = imageInfo.getHeight(); int width = imageInfo.getWidth(); layoutParams.width = imageWidth; layoutParams.height = (int) ((float) (imageWidth * height) / (float) width); simpleDraweeView.setLayoutParams(layoutParams
); } @Override public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) { Log.d("TAG", "Intermediate image received"); } @Override public void onFailure(String id, Throwable throwable) { throwable.printStackTrace(); } }; DraweeController controller = Fresco.newDraweeControllerBuilder().setControllerListener(controllerListener).setUri(Uri.parse(imagePath)).build(); simpleDraweeView.setController(controller); } }