android gif动画解决 fresco方法 Android Studio 3.0环境
2018-03-07 11:26
399 查看
加载和播放顺滑流畅,推荐使用
1、引入fresco
编辑 build.gradle 文件
当然,这里的0.12.0可以修改为其他版本,版本可以到官方 https://github.com/facebook/fresco去查看一下。
注意,如果出现了引入无法合并的问题,如下
我用了笨方法,依次去掉后边的compile,挨个测试,虽然笨但是有效
2、在xml布局文件中, 加入命名空间:
加入SimpleDraweeView:
3、java代码添加,开始加载图片:
1、引入fresco
编辑 build.gradle 文件
dependencies { // 其他依赖 compile 'com.facebook.fresco:fresco:0.12.0' / 在 API < 14 上的机器支持 WebP 时,需要添加 compile 'com.facebook.fresco:animated-base-support:0.12.0' // 支持 GIF 动图,需要添加 compile 'com.facebook.fresco:animated-gif:0.12.0' // 支持 WebP (静态图+动图),需要添加 compile 'com.facebook.fresco:animated-webp:0.12.0' compile 'com.facebook.fresco:webpsupport:0.12.0' // 仅支持 WebP 静态图,需要添加 compile 'com.facebook.fresco:webpsupport:0.12.0' }
当然,这里的0.12.0可以修改为其他版本,版本可以到官方 https://github.com/facebook/fresco去查看一下。
注意,如果出现了引入无法合并的问题,如下
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
我用了笨方法,依次去掉后边的compile,挨个测试,虽然笨但是有效
2、在xml布局文件中, 加入命名空间:
<!-- 其他元素--> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent" android:layout_width="match_parent">
加入SimpleDraweeView:
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable"/>
3、java代码添加,开始加载图片:
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png"); SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view); /**加载静态图 draweeView.setImageURI(uri); */ /**加载gif图 */ DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(uri) .setAutoPlayAnimations(true) .build(); draweeView.setController(controller);
相关文章推荐
- android使用Fresco显示gif图并控制动画,解决动画为空null的问题
- linux ubuntu环境下 android jdk sdk eclipse adt 以及手机连接无法识别的解决方法
- 终于搞定多张JPG图片转成GIF动画这个难题,解决方法如下。
- Android 开发环境搭建 与在编译中遇到错误make Error 45解决方法
- [Android实例] 最新android studio注意事项打不开等问题6种解决方法
- Android开发动画效果被遮掉的解决方法
- Mac OS X下搭建Android Source编译环境的问题及解决方法
- GIF动画图片在IE中不能正常显示的解决方法
- 才发现的超链接js导致网页中GIF动画停止的解决方法
- [Android环境搭建错误解决三]Android4.0.4源码编译常见错误及解决方法
- cocos2dx3.0 添加第三方库,VS编译环境和Android编译环境添加方法
- Mac下cocos2dx-3.0打包Android时,提示"SimpleAudioEngine.h"not found的解决方法
- 才发现的超链接js导致网页中GIF动画停止的解决方法
- android eclipse开发环境 自动提示 程序无法响应解决方法
- Android Activity切换动画overridePendingTransition 笔记 . 解决切换无响应的方法
- Android 动画 setVisibility 后出错解决方法
- Android开发环境搭建和常见问题的解决方法
- TBitmap resize在 android编译环境下 JNI调用方式出错的解决方法!!!
- Eclipse搭建Android开发环境之ADT安装常见错误及解决方法
- android环境下解决java.io.IOException: Malformed ipv6异常的方法