compile 'com.facebook.fresco:imagepipeline-okhttp3:0.11.0' compile 'com.facebook.fresco:fresco:0.12.0' compile 'com.facebook.fresco:animated-base-support:0.12.0' compile 'com.facebook.fresco:animated-gif:0.12.0'
activity_main
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="app.my.com.myapplication.MainActivity"> <com.facebook.drawee.view.SimpleDraweeView android:id="@+id/simp" android:layout_width="300dp" android:layout_height="300dp" /> </LinearLayout>
MainActivity
package app.my.com.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; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SimpleDraweeView draweeView = findViewById(R.id.simp); Uri uri2 = Uri.parse("http://img2.ph.126.net/uzguQM3gqa3NcK2XaOD3FA==/6631646108817614243.gif"); DraweeController mDraweeController = Fresco.newDraweeControllerBuilder() .setAutoPlayAnimations(true) .setUri(uri2)//设置uri .build(); draweeView.setController(mDraweeController); } }MyApplication
package app.my.com.myapplication; import android.app.Application; import com.facebook.drawee.backends.pipeline.Fresco; /** * Created by lenovo on 2017/12/09. */ public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.my.com.myapplication"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>