我需要实现循环进度条,以便在Fresco下载图像时显示和更新。该类必须根据Fresco方法setProgressBarImage()的要求从Drawable扩展。
我的班级正在使用Fresco加载图片,如下面的代码段:
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.image);
simpleDraweeView.getHierarchy().setProgressBarImage(new ProgressBarDrawable());
simpleDraweeView.setImageURI(message.getMessageImage().getImageFileUriForList());
“image”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没有提供循环进度条可绘制。
有没有人有这方面的实施想法?
答案 0 :(得分:4)
您可以实现Drawable
,因为ProgressBarDrawable
只是实现和覆盖超级方法。如前所述,此问题应视为重复。
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);
}
}
答案 1 :(得分:2)
您可以使用Fresco Library Sample for CircularProgressDrawable中给出的代码。 https://github.com/facebook/fresco/blob/master/samples/contrib/com/facebook/drawee/drawable/CircleProgressBarDrawable.java
但是上面的代码中存在一个问题,它使椭圆形而不是圆形,以解决您可能使用以下代码的问题。
https://gist.github.com/sheerazam/ef701a564624d5f6d6c632e0d254cd15