Fresco官方文档上写着,DraweeView必须固定宽高,如下图,那么如果我们要动态改变SimpleDraweeView的宽高,该如何做呢?
其实很简单,就像改变ImageView的宽高那样就行了。
改变ImageView的宽高:
ImageView img = (ImageView) findViewById(R.id.img);
LayoutParams params = (LayoutParams) img.getLayoutParams();
params.width = width;//指定值
params.height = height; (px为单位)
img.setLayoutParams(params);
同样地,改变SimpleDraweeView的宽高:
SimpleDraweeView draweeView = (SimpleDraweeView) view.findViewById(R.id.draweeView );
LayoutParams params = (LayoutParams) draweeView.getLayoutParams();
params.width=width;
params.height=height;
draweeView.setLayoutParams(params);
在xml中:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/draweeView "
android:layout_width="50dp"
android:layout_height="50dp"
fresco:actualImageScaleType="fitXY"
/>