我需要实现一个圆形进度条来显示和更新,而Fresco下载图像。该类必须按照Fresco的方法setProgressBarImage()的要求从Drawable扩展。
我的类使用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没有提供可绘制的圆形进度条。
有没有人对此有一个实现的想法?
发布于 2016-01-21 20:47:32
您可以只实现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);
}
}发布于 2016-10-06 19:15:58
您可以使用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
https://stackoverflow.com/questions/34910616
复制相似问题