Fresco 框架配置说明文档(更新中)
来源:互联网 发布:用友软件单机版 编辑:程序博客网 时间:2024/04/29 19:33
Fresco图片优化性能比ImageLoader好,开始使用Fresco框架
直接通过Library Dependency 导入Fresco的包
com.facebook.fresco:fresco:0.9.0
<!-- 访问网络的权限 -->
<uses-permission android:name="android.permission.INTERNET"/>
调用的类里面配置说明:
调用 setContentView() 之前,进行初始化:
配置Image Pipeline 编辑和纠错
对于大多数的应用,Fresco的初始化,只需要以下一句代码:
Fresco.initialize(context);
对于那些需要更多进一步配置的应用,我们提供了ImagePipelineConfig。
以下是一个示例配置,列出了所有可配置的选项。几乎没有应用是需要以下这所有的配置的,列出来仅仅是为了作为参考。
ImagePipelineConfig config = ImagePipelineConfig.newBuilder()
.setBitmapMemoryCacheParamsSupplier(bitmapCacheParamsSupplier)
.setCacheKeyFactory(cacheKeyFactory)
.setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)
.setExecutorSupplier(executorSupplier)
.setImageCacheStatsTracker(imageCacheStatsTracker)
.setMainDiskCacheConfig(mainDiskCacheConfig)
.setMemoryTrimmableRegistry(memoryTrimmableRegistry)
.setNetworkFetchProducer(networkFetchProducer)
.setPoolFactory(poolFactory)
.setProgressiveJpegConfig(progressiveJpegConfig)
.setRequestListeners(requestListeners)
.setSmallImageDiskCacheConfig(smallImageDiskCacheConfig)
.build();
Fresco.initialize(context, config);
请记得将配置好的ImagePipelineConfig 传递给 Fresco.initialize! 否则仍旧是默认配置。
在xml布局文件中, 加入命名空间:
xmlns:fresco="http://schemas.android.com/apk/res-auto"
Drawees 具有极大的可定制性。
下面的例子给出了可以配置的各种选项:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_width="20dp" //宽度
android:layout_height="20dp" //高度
fresco:fadeDuration="300"
fresco:actualImageScaleType="focusCrop"
fresco:placeholderImage="@color/wait_color"
fresco:placeholderImageScaleType="fitCenter"
fresco:failureImage="@drawable/error"
fresco:failureImageScaleType="centerInside" //图片缩放类型
fresco:retryImage="@drawable/retrying" //再次加载图片显示
fresco:retryImageScaleType="centerCrop" //再次加载图片显示的缩放类型
fresco:progressBarImage="@drawable/progress_bar" //显示进度条
fresco:progressBarImageScaleType="centerInside" //显示进度条的缩放类型
fresco:progressBarAutoRotateInterval="1000" //进度条显示时间
fresco:backgroundImage="@color/blue" //背景颜色
fresco:overlayImage="@drawable/watermark"
fresco:pressedStateOverlayImage="@color/red"
fresco:roundAsCircle="false"
fresco:roundedCornerRadius="1dp" //园角弧度
fresco:roundTopLeft="true"
fresco:roundTopRight="false"
fresco:roundBottomLeft="false"
fresco:roundBottomRight="true"
fresco:roundWithOverlayColor="@color/corner_color"
fresco:roundingBorderWidth="2dp"
fresco:roundingBorderColor="@color/border_color"
/>
强制性的宽高 你必须声明 android:layout_width 和 android:layout_height。
如果没有在XML中声明这两个属性,将无法正确加载图像。
Drawees 不支持 wrap_content 属性。
所下载的图像可能和占位图尺寸不一致,如果设置出错图或者重试图的话,
这些图的尺寸也可能和所下载的图尺寸不一致。
如果大小不一致,假设使用的是 wrap_content,图像下载完之后,
View将会重新layout,改变大小和位置。这将会导致界面跳跃。
固定宽高比
只有希望显示固定的宽高比时,可以使用wrap_content。
如果希望图片以特定的宽高比例显示,例如 4:3,可以在XML中指定:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_width="20dp"
android:layout_height="wrap_content"
fresco:viewAspectRatio="1.33"
<!-- other attributes -->
具体的调用方法
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/fresco-logo.png");
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
更详细的说明请看 http://www.fresco-cn.org/
public class FrescoUtils { /** * @param activity * @param id * @param url */ public static void displayImage(Activity activity,int id,String url){ SimpleDraweeView simpleDraweeView = (SimpleDraweeView)activity.findViewById(id); Uri imageUri = Uri.parse(url); simpleDraweeView.setImageURI(imageUri); }}
- Fresco 框架配置说明文档(更新中)
- Fresco 中文文档: Fresco | Fresco 中文说明
- Fresco(Facebook开源的android项目)图片缓存框架的eclipse整合与使用探索(较详细配置说明)
- Nginx配置文档说明
- vsftpd配置文档说明
- Fresco 使用要点(不定期更新)
- Facebook新开源框架Fresco(转载)
- 模型框架配置说明
- string类详细说明(更新中)
- 关于在项目中使用三方框架见解(volley和fresco)
- j2me框架教程(3)--xml文档详细说明
- lua的更新文档(翻译中)
- jquery 学习文档(更新中)
- 微信小程序 整理文档(更新中。。。)
- MQ配置文档说明手册
- MQ配置文档说明手册
- HighCharts中文配置说明文档
- GoldenGate 配置文档解析说明
- JSON压缩:JSONMinify
- Git常用命令总结
- 配置freeglut和glew
- Android依赖注入:Dagger、RoboGuice和ButterKnife
- Android Stuido快捷键
- Fresco 框架配置说明文档(更新中)
- Android内/外部存储文件读写操作总结
- C++需要记住的一些点
- 修改Mac命令提示符
- 四中启动模式和onNewIntent的关系
- 不用itunes帐号如何打ipa包
- C#项目调用C++的DLL程序
- 初学php(二)
- 服务器端主动关闭连接, 产生的TIME_WAIT状态为什么会占用服务端大量端口?