安卓高级Fresco图片框架的时候

时间:2022-10-05 13:49:48

Fresco:2015FaceBook推出的 及其强大

支持webp图片格式

和渐进式图片加载

中文文档

使用方法

  1. 引入依赖

    点击查看具体教程

  2. 基本使用步骤

    1. 在布局中使用其标签 <com.facebook.drawee.view.SimpleDraweeView/>

      注意不能使用包裹内容
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.administrator.myapplication.MainActivity"> <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_width="200dp"
android:layout_height="200dp"
fresco:placeholderImage="@mipmap/ic_launcher"
/>
</RelativeLayout>

注意需要初始化:

public class Myappaliction extends Application{

    @Override
public void onCreate() {
super.onCreate(); Fresco.initialize(this);
}
}
package com.example.administrator.myapplication;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder; public class MainActivity extends AppCompatActivity {
private SimpleDraweeView show_iv;
private String path = "http://img.hb.aicdn.com/761f1bce319b745e663fed957606b4b5d167b9bff70a-nfBc9N_fw580";
private String gifPath = "http://img.zcool.cn/community/012f4d5542e7de0000019ae98b8ef1.jpg"; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uri = Uri.parse(gifPath);
//以下方法使用渐进式并直接播放动态图
show_iv=(SimpleDraweeView) findViewById(R.id.my_image_view);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(true) .build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request) .setAutoPlayAnimations(true)//
.setOldController(show_iv.getController())
.build();
show_iv.setController(controller); }
}