1. 程式人生 > >Fresco載入靜態圖片

Fresco載入靜態圖片

1,匯入依賴
implementation ‘com.facebook.fresco:fresco:1.11.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 murl="http://www.zhaoapi.cn/images/quarter/ad1.png";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sdv = findViewById(R.id.sdv);

        Uri parse = Uri.parse(murl);
        sdv.setImageURI(parse);
        
    }
}