Android Fresco - SimpleDraweeView 圆形动图设置

Layout:

 
        


代码:

    /**
     * @param imageView
     * @param url
     * @param suffix
     * @param isCircle  0:false 1:Circle 2:Round
     */
    public static void setImage(SimpleDraweeView imageView, String url, int isCircle) {

        if (url != null) {

            Uri parse = Uri.parse(url);
            String[] split = url.split("\\.");
            if (split.length > 1 && split[split.length - 1].equalsIgnoreCase("gif")) { //如果是动图  则用代码设置
                DraweeController controller = Fresco.newDraweeControllerBuilder()
                        .setUri(parse).setAutoPlayAnimations(true).build();
                imageView.setController(controller);

                switch (isCircle) {//如果是圆形 用代码设置(Layout里必须设置背景)
                    case Constants.CIRCLE:// 自定义变量 用来判断是不是圆形
                        setCircle(imageView);
                        break;
                }

            } else {
                imageView.setImageURI(parse);
            }
        } else {
            imageView.setImageURI(Constants.PROPHETSIMGURL);
        }
    }

    private static void setCircle(SimpleDraweeView imageView) {
        RoundingParams roundingParams = imageView.getHierarchy().getRoundingParams();
        roundingParams.setRoundAsCircle(true);
        imageView.getHierarchy().setRoundingParams(roundingParams);
    }




ps:

参考资料

fresco 加载本地图片、gif资源

fresco 使用要点(不定期更新)

fresco Api

fresco 图片加载(一)

fresco 图片加载(二)

fresco 图片加载(三)



你可能感兴趣的:(Android,android,Fresco,GIF)