Fresco 圓形 圓角 動圖
阿新 • • 發佈:2019-02-18
新增依賴:
compile 'com.facebook.fresco:fresco:0.12.0'
// 支援 GIF 動圖,需要新增 compile 'com.facebook.fresco:animated-gif:0.12.0' // 支援 WebP (靜態圖+動圖),需要新增 compile 'com.facebook.fresco:animated-webp:0.12.0' compile 'com.facebook.fresco:webpsupport:0.12.0' // 僅支援 WebP 靜態圖,需要新增 compile 'com.facebook.fresco:webpsupport:0.12.0'
[MyApplication.java] public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fresco="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent" android:layout_width="match_parent">
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" />
fresco:fadeDuration=
"300"
// 淡入淡出的持續時間
fresco:actualImageScaleType=
"focusCrop"
// 實際影象的縮放型別
fresco:placeholderImage=
"@color/wait_color"
//佔位圖
fresco:placeholderImageScaleType=
"fitCenter"
//佔位圖的縮放型別
fresco:failureImage=
"@drawable/error"
//下載失敗顯示的圖片
fresco:failureImageScaleType=
"centerInside"
//失敗圖的縮放型別
fresco:retryImage=
"@drawable/retrying"
//圖片載入失敗時顯示,提示使用者點選重新載入,重複載入4次還是沒有加載出來的時候才會顯示failureImage的圖片
fresco:retryImageScaleType=
"centerCrop"
//重新載入的圖片縮放型別
fresco:progressBarImage=
"@drawable/progress_bar"
//進度條圖片
fresco:progressBarImageScaleType=
"centerInside"
fresco:progressBarAutoRotateInterval=
"1000"
//進度圖自動旋轉間隔時間(單位:毫秒ms)
fresco:backgroundImage=
"@color/blue"
//背景圖片,這裡的背景圖片首先被繪製
fresco:overlayImage=
"@drawable/watermark"
// 設定疊加圖,在xml中只能設定一張疊加圖片,如果需要多張圖片的話,需要在java程式碼中設定哦
fresco:pressedStateOverlayImage=
"@color/red"
// 設定點選狀態下的疊加圖
fresco:roundAsCircle=
"false"
//設定為圓形圖
fresco:roundedCornerRadius=
"1dp"
// 圓角半徑
fresco:roundTopLeft=
"true"
// 左上角是否為圓角
fresco:roundTopRight=
"false"
fresco:roundBottomLeft=
"false"
fresco:roundBottomRight=
"true"
fresco:roundWithOverlayColor=
"@color/corner_color"
fresco:roundingBorderWidth=
"2dp"
//邊框的寬度
fresco:roundingBorderColor=
"@color/border_color"
//邊框顏色
圓角動圖:
SimpleDraweeView sld = (SimpleDraweeView)findViewById(R.id.sld); Uri ur = Uri.parse("https://upfile.asqql.com/2009pasdfasdfic2009s305985-ts/2018-4/20184202030624799.gif"); sld.setImageURI(ur); //自動動圖 DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(ur) .setAutoPlayAnimations(true) .build(); sld.setController(controller); //圓角 // GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); RoundingParams roundingParams = RoundingParams.fromCornersRadius(50f); roundingParams.setRoundAsCircle(true); roundingParams.setBorder(Color.BLUE,1); roundingParams.setOverlayColor(Color.WHITE); roundingParams.setCornersRadius(30f); sld.getHierarchy().setRoundingParams(roundingParams);