2016-01-20 110 views
4

我需要實現一個圓形進度條來顯示和更新,而Fresco下載圖像。該類必須根據Fresco的方法setProgressBarImage()的要求擴展到Drawable。使用壁畫的圓形進度條

我的階級是使用壁畫加載像下面的代碼片段的圖像:

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

和XML的「形象」 SimpleDraweeView如下:

<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

的[如何創建Android的圓形進度?](http://stackoverflow.com/questions/27213381/how-to-create-circular-progressbar-in-android) – piotrek1543

+2

可能的複製@ piotrek1543:這不是重複的,因爲我特別需要一個按照Fresco的要求從Drawable延伸的Progressbar。無論如何,這個問題太廣泛了。答案並不能解決我的問題。 –

回答

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); 
} 

} 
+0

謝謝,很好的例子 –