Fresco动态图片获取

    此依赖用作与fresco依赖一起使用,实现获取动态图
    compile 'com.facebook.fresco:fresco:0.12.0'

    compile 'com.facebook.fresco:animated-gif:0.12.0'


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

   

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:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.dell.a1511r0410.MainActivity">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/main_sdv"
        android:layout_width="300px"
        android:layout_height="300px"
        android:layout_centerInParent="true"
        >com.facebook.drawee.view.SimpleDraweeView>

RelativeLayout>

   

    

package com.example.dell.a1511r0410;

import android.app.Application;
import com.facebook.drawee.backends.pipeline.Fresco;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        //初始化Fresco使用默认配置
        Fresco.initialize(this);
    }
}

    

    

package com.example.dell.a1511r0410;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;

public class MainActivity extends AppCompatActivity {

    private SimpleDraweeView main_sdv;



    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //找到资源控件的ID
        main_sdv = findViewById(R.id.main_sdv);
        
        //实现动态图
        Uri uri = Uri.parse("http://img3.a0bi.com/upload/ttq/20151215/1450174793747.jpg");
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri(uri)
                .setAutoPlayAnimations(true)
                .build();

        //开始下载,实现动态图
        main_sdv.setController(controller);
    }
}

你可能感兴趣的:(Fresco动态图片获取)