Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法适配RecyclerView #18

Open
yline opened this issue Feb 9, 2018 · 1 comment
Open

无法适配RecyclerView #18

yline opened this issue Feb 9, 2018 · 1 comment

Comments

@yline
Copy link

yline commented Feb 9, 2018

LoadingDrawable + Fresco + RecyclerView
场景:RecyclerView 加载两列,每个Item使用Fresco自带的View;
setProgressImage(LoadingDrawable);
目标:使用LoadingDrawable,实现Fresco加载过程的动画,即:LoadingDrawable一直播放,指导Fresco加载完成,加载完图片

问题:LoadingDrawable变形了。 分析可能原因:Fresco因为RecyclerView导致,给定LoadingDrawable的高度和宽度,比例变成了,2:1;导致LoadingDrawable变形了

@yline
Copy link
Author

yline commented Feb 9, 2018

解决方案: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));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant