<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:orientation="vertical" 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="com.z.bwie.a01_fresco.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="fresco加载图片" android:onClick="jiazai"/> <com.facebook.drawee.view.SimpleDraweeView android:background="#000" android:layout_width="300dp" android:layout_height="300dp" android:id="@+id/drawee_view" app:placeholderImage="@drawable/icon_placeholder" app:placeholderImageScaleType="fitCenter" app:actualImageScaleType="focusCrop" app:progressBarImage="@drawable/icon_progress_bar" app:progressBarImageScaleType="centerInside" app:progressBarAutoRotateInterval="2000" app:failureImage="@drawable/icon_failure" app:failureImageScaleType="centerInside" app:retryImage="@drawable/icon_retry" app:retryImageScaleType="centerCrop" app:fadeDuration="3000" app:backgroundImage="@color/colorAccent" app:roundedCornerRadius="50dp" app:roundBottomLeft="true" app:roundTopLeft="true" app:roundBottomRight="true" app:roundTopRight="true" app:roundingBorderColor="#fff" app:roundingBorderWidth="10dp" /> </LinearLayout>
Fresco.initialize(this); import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; 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 String imageUrl = "https://m.360buyimg.com//n0//jfs//t6700//155//2098998076//156185//6cf95035//595dd5a5Nc3a7dab5.jpg"; private SimpleDraweeView drawee_view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawee_view = (SimpleDraweeView) findViewById(R.id.drawee_view); } public void jiazai(View view){ Uri uri=Uri.parse(imageUrl); drawee_view.setImageURI(uri); DraweeController controller = Fresco.newDraweeControllerBuilder() //加载图片的地址 .setUri(uri) //设置点击重试是否开启 .setTapToRetryEnabled(true) //设置旧的Controller .setOldController(drawee_view.getController()) //构建 .build(); //设置DraweeController drawee_view.setController(controller); } }