我想我终于找到了解决方案,首先使用 FIT_XY 缩放图像,然后将“newHeight”设置为图像视图的高度
imageView.setScaleType(ScaleType.FIT_XY);
imageView.getLayoutParams().height = newHeight;
代码片段
Ion.with(imageView)
.animateGif(AnimateGifMode.ANIMATE)
.load(imgUrl)
.setCallback(new FutureCallback < ImageView > () {
@SuppressLint("NewApi")
@Override
public void onCompleted(Exception arg0,
ImageView arg1) {
imageView.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
imageView.getViewTreeObserver()
.removeOnPreDrawListener(this);
imageView.setScaleType(ScaleType.FIT_XY);
imageView.getLayoutParams().height = newHeight;
return true;
}
});
}
});