您的位置:首页 > 其它

[置顶] Fresco图片加载框架学习和那些坑

2017-01-25 21:45 295 查看
1.

compile 'com.facebook.fresco:fresco:0.12.0'
// 支持 GIF 动图,需要添加
compile 'com.facebook.fresco:animated-gif:0.12.0'

可选项:

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'
}

开始使用 Fresco

如果你仅仅是想简单下载一张网络图片,在下载完成之前,显示一张占位图,那么简单使用SimpleDraweeView 即可。SimpleDraweeView 什么鬼一个自定义的Imageview
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}
布局中使用(注意了:

强制性的宽高

你必须声明 
android:layout_width
 和 
android:layout_height
。如果没有在XML中声明这两个属性,将无法正确加载图像。

wrap_content

Drawees 不支持 
wrap_content
 属性。所下载的图像可能和占位图尺寸不一致,如果设置出错图或者重试图的话,这些图的尺寸也可能和所下载的图尺寸不一致。如果大小不一致,假设使用的是 
wrap_content
,图像下载完之后,View将会重新layout,改变大小和位置。这将会导致界面跳跃。,)
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_width="200dp"
android:layout_height="wrap_content"
fresco:roundedCornerRadius="5dp"
fresco:roundBottomLeft="false"
fresco:roundBottomRight="false"
fresco:roundWithOverlayColor="#0000ff"
fresco:roundingBorderWidth="1dp"
fresco:roundingBorderColor="#ff0000"
fresco:viewAspectRatio="1.33"
fresco:placeholderImage="@mipmap/ic_launcher"
/>
act 中使用
final Uri uri = Uri.parse("http://n.sinaimg.cn/eladies/20170103/vIpy-fxzencv3828038.jpg");
draweeView= (SimpleDraweeView) findViewById(R.id.my_image_view);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

draweeView.setImageURI(uri);
}
});
更多酷炫功能参考一下doc 官网(定制网络底层,加载自定义view ,和Vollery结合,和Okhttp ,多图复用)
https://www.fresco-cn.org/docs/using-drawees-xml.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: