Fresco載入動態圖片
阿新 • • 發佈:2018-12-27
1,匯入依賴
implementation ‘com.facebook.fresco:animated-gif:1.10.0’
2,activity_main
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"/>
3,寫一個Application類初始化Fresco
public class Application extends android.app.Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}
4.MainActivity
public class MainActivity extends AppCompatActivity { private SimpleDraweeView sdv; private String nurl="http://www.zhaoapi.cn/images/girl.gif"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sdv = findViewById(R.id.sdv); DraweeController controller= Fresco.newDraweeControllerBuilder() .setUri(nurl) .setAutoPlayAnimations(true) .build(); sdv.setController(controller); } }