LoadingDrawable
LoadingDrawable copied to clipboard
无法适配RecyclerView
LoadingDrawable + Fresco + RecyclerView
场景:RecyclerView 加载两列,每个Item使用Fresco自带的View;
setProgressImage(LoadingDrawable);
目标:使用LoadingDrawable,实现Fresco加载过程的动画,即:LoadingDrawable一直播放,指导Fresco加载完成,加载完图片
问题:LoadingDrawable变形了。 分析可能原因:Fresco因为RecyclerView导致,给定LoadingDrawable的高度和宽度,比例变成了,2:1;导致LoadingDrawable变形了
解决方案:LoadingDrawable中,有一个系统回调: protected void onBoundsChange(Rect bounds)
该方法中,对bounds进行校对,即:匹配成宽高比为,1:1
具体为:LoadingDrawable.java @Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds);
int width = bounds.width();
int height = bounds.height();
int minSize = Math.min(Math.abs(width), Math.abs(height));
int right = bounds.left + (width > 0 ? minSize : -minSize);
int bottom = bounds.top + (height > 0 ? minSize : -minSize);
this.mLoadingRender.setBounds(new Rect(bounds.left, bounds.top, right, bottom));
}