1,studio添加fresco的jar包依賴使用括号裡面的就行(compil 'com.facebook.fresco:fresco:0.8.1') 加載gif不要用高版本的Fresco;
2,寫xml檔案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="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="com.example.myapplication.MainActivity">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sim_fre"
android:layout_width="200dp"
android:layout_height="200dp"
fresco:placeholderImage="@mipmap/ic_launcher"/>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fresco.initialize(this);//初始化在加載布局的上面
setContentView(R.layout.activity_main);
SimpleDraweeView s=(SimpleDraweeView)this.findViewById(R.id.sim_fre);
DraweeController mDraweeController = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
//設定uri,加載本地的gif資源
.setUri(Uri.parse("res://"+getPackageName()+"/"+R.drawable.e))//設定uri
.build();
//設定Controller
s.setController(mDraweeController);
}
}