Fresco的配置及使用
来源:互联网 发布:华天软件科技有限公司 编辑:程序博客网 时间:2024/06/06 05:43
Fresco是一个强大的图片加载组件,支持Android2.3及其以后的版本
如何在项目中引入 Fresco:
使用 Android Studio构建一个项目
编辑 build.gradle
文件:在dependencies下添加依赖(选择所需的)
// 在 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'
如果是网络图片,则需要添加权限
<uses-permission android:name="android.permission.INTERNET" />
在加载图片之前,你必须初始化Fresco
类。你只需要调用Fresco.initialize
一次即可完成初始化,在Application
里面做这件事再适合不过了(如下面的代码),注意多次的调用初始化是无意义的。
新建一个类,继承Application
public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();Fresco.initialize(this);}}
然后在 AndroidManifest.xml
中指定你的 Application 类,通过name
<application ... android:label="@string/app_name" android:name=".MyApplication" > ... </application>
在xml布局文件中,添加布局
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" />
开始加载图片:
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);
这样就可以通过Fresco加载图片了
阅读全文
0 0
- Fresco的配置及使用
- Fresco的介绍及使用
- Fresco的简单介绍及简单使用
- Fresco的使用及圆角
- Fresco的使用
- Fresco的简单使用
- Fresco的使用
- Fresco的初步使用
- Fresco的使用
- Fresco的使用<一>
- Fresco的简单使用
- Fresco的使用
- 框架Fresco的使用
- Fresco的基本使用
- Fresco的使用
- Fresco的使用
- fresco的初次使用
- Fresco的基本使用
- Button点击时滑动的事件传递
- HDU 5934-Bomb(强连通缩点)
- maven初使用:maven安装配置教程
- mysql5.6主从复制搭建
- spring 中.properties加载顺序
- Fresco的配置及使用
- ubuntu14.04 LTS版本下安装配置gem5环境
- 野指针
- The import org.springframework.test.context.junit4.SpringJUnit4ClassRunner cannot be resolved
- Algorithms Edition 4 chapter 1 percolation 算法第一章课后作业
- 英版树莓派更改键盘布局
- Django 时间与时区设置问题
- 初识JavaScript依赖注入
- 树莓派更换软件源