我需要实现一个圆形进度条,以便在Fresco下载图像时进行显示和更新。该类必须按照Fresco方法setProgressBarImage()的要求从Drawable扩展。

我的类(class)是使用Fresco加载图像,如下所示:

SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.image);
simpleDraweeView.getHierarchy().setProgressBarImage(new ProgressBarDrawable());
simpleDraweeView.setImageURI(message.getMessageImage().getImageFileUriForList());

“图像” SimpleDraweeView的XML如下:
<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/image"
    android:layout_width="192dp"
    android:layout_height="200dp"
    android:layout_margin="7dp"
    android:layout_gravity="center"
    fresco:actualImageScaleType="fitCenter"
    tools:background="@drawable/gallery_attach_dialog" />

问题是我需要用一个圆形的替换这个标准的水平进度条。而且Fresco没有提供可绘制的圆形进度条。

有人对此有实现的想法吗?

最佳答案

您可以只实现Drawable,因为ProgressBarDrawable只是实现和覆盖 super 方法。如前所述,该问题应视为重复的。

public class ImageLoadProgressBar extends ProgressBarDrawable {


float level;

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

int color = whatevercolorresource;

final RectF oval = new RectF();

int radius = whateverradius;

public ImageLoadProgressBar(){
    paint.setStrokeWidth(whateveintyouputhere);
    paint.setStyle(Paint.Style.STROKE);
}

@Override
protected boolean onLevelChange(int level) {
    this.level = level;
    invalidateSelf();
    return true;
}

@Override
public void draw(Canvas canvas) {
    oval.set(canvas.getWidth() / 2 - radius, canvas.getHeight() / 2 - radius,
            canvas.getWidth() / 2 + radius, canvas.getHeight() / 2 + radius);

    drawCircle(canvas, level, color);
}


private void drawCircle(Canvas canvas, float level, int color) {
    paint.setColor(color);
    float angle;
    angle = 360 / 1f;
    angle = level * angle;
    canvas.drawArc(oval, 0, Math.round(angle), false, paint);
}

}

10-08 03:00