本教程內(nèi)容來(lái)源于:http://fresco-cn.org
采用 知識(shí)共享 署名 4.0 國(guó)際 許可協(xié)議 進(jìn)行許可
mSimpleDraweeView.setImageURI(uri);
如果要更加復(fù)雜的配置,可使用ControllerBuilder;
一般情況下,在XML設(shè)置顯示效果即可, 如果想更多定制化,可以這樣:
創(chuàng)建一個(gè) builder 然后設(shè)置給 DraweeView:
List<Drawable> backgroundsList;
List<Drawable> overlaysList;
GenericDraweeHierarchyBuilder builder =
new GenericDraweeHierarchyBuilder(getResources());
GenericDraweeHierarchy hierarchy = builder
.setFadeDuration(300)
.setPlaceholderImage(new MyCustomDrawable())
.setBackgrounds(backgroundList)
.setOverlays(overlaysList)
.build();
mSimpleDraweeView.setHierarchy(hierarchy);
對(duì)于同一個(gè)View,請(qǐng)不要多次調(diào)用setHierarchy,即使這個(gè)View是可回收的。創(chuàng)建 DraweeHierarchy 的較為耗時(shí)的一個(gè)過(guò)程,應(yīng)該多次利用。
如果要改變所要顯示的圖片可使用setController 或者 setImageURI。
DraweeHierarchy 的一些屬性可以在運(yùn)行時(shí)改變。
要改變這些屬性,首先獲取一個(gè)引用:
GenericDraweeHierarchy hierarchy = mSimpleDraweeView.getHierarchy();
修改占位圖為資源id:
hierarchy.setPlaceholderImage(R.drawable.placeholderId);
或者修改為一個(gè) Drawable:
Drawable drawable;
// 創(chuàng)建一個(gè)drawable
hierarchy.setPlaceholderImage(drawable);
修改縮放類(lèi)型:
hierarchy.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE);
當(dāng)然,如果修改為 focusCrop, 需要指定一個(gè)居中點(diǎn):
hierarchy.setActualImageFocusPoint(point);
或者設(shè)置一個(gè)color filter:
ColorFilter filter;
// 創(chuàng)建filter
hierarchy.setActualImageColorFilter(filter);
All of the rounding related params, except the rounding method, can be modified. You get a RoundingParams object from the hierarchy, modify it, and set it back again:
除了圓角顯示方式(原來(lái)為圓角的不能修改為圓圈,反之亦然),其他圓角相關(guān)的呈現(xiàn)參數(shù), 具體參見(jiàn)這里 是可以動(dòng)態(tài)修改的。
如下: 獲取DraweeHierarchy的圓角顯示參數(shù),修改圓角半徑為10。
java
RoundingParams roundingParams = hierarchy.getRoundingParams();
roundingParams.setCornersRadius(10);
hierarchy.setRoundingParams(roundingParams);