我使用AndroidStudio开发,以下情况,针对studio
1、在build.gradle的dependencies中加入

 compile 'com.facebook.fresco:fresco:0.9.0+'

:这是github上的开源项目。写博客的时候,版本是这个,在使用前,请确认版本
github链接

https://github.com/facebook/fresco

我这里对原Demo做了分析。如果想看github上的原Demo


2、在清单文件中,加上网络权限

 <uses-permission android:name="android.permission.INTERNET" />

3、创建自己的Application,在onCreate方法中注册

public void onCreate() {        super.onCreate();        Fresco.initialize(this);    }

4、布局文件

<com.facebook.drawee.view.SimpleDraweeView        android:id="@+id/ani_image"        android:layout_width="match_parent"        android:layout_height="300dp"        android:layout_below="@id/logo_image"        android:layout_centerHorizontal="true"        android:layout_marginTop="20dp"        fresco:placeholderImage="@color/image_placeholder" />

注:宽高如果都是wrap_content或者match_parent,就不会显示图片,宽和高里面,最少要有一个具体的值

5、使用代码:

SimpleDraweeView aniView = (SimpleDraweeView) findViewById(R.id.ani_image);        //gif类型的动态图        Uri aniImageUri2 = Uri.parse("http://images.cnfol.com//file//201603//mp35337118_1444701483338_2_201603250855265951.gif");        //普通图片        Uri aniImageUri1 = Uri.parse("http://images.cnfol.com//file//201603//fang_201603240925207041.jpg");        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(aniImageUri2)                .build();        DraweeController controller = Fresco.newDraweeControllerBuilder()                .setImageRequest(request)                .setAutoPlayAnimations(true)                .build();        aniView.setController(controller);

更多相关文章

  1. 基于ndk-r21b编译ffmpeg-4.3.1
  2. 从android相册获取所有图片的路径
  3. android画图------字节数组转化为图片
  4. [代码片段] 【转】Android以最省内存的方式读取本地资源的
  5. 用java的jdk 生成android 的jni接口文档
  6. android 运行时生成dex文件,并装载调用
  7. 测试为Android模拟器创建和管理sdcard image文件
  8. Android通过LIstView显示文件列表的两种方法介绍
  9. Android(安卓)Studio gradle 使用最新版本的 xstream:1.4.8 出错

随机推荐

  1. Android(安卓)不能使用内部资源
  2. Android(安卓)使用WindowManager打造通用
  3. IntentService简介
  4. Android(安卓)[Camera 源码] 相机 HAL3(C
  5. Android(安卓)canvas PaintFlagsDrawFilt
  6. Android利用WebService查询手机号码归属
  7. Android不让弹出键盘挡住View
  8. 转:Android文件操作总结
  9. Android(安卓)Studio中Textview里字体颜
  10. android ActionBarImpl can only be used