1

I want to create a progress bar as specified in the image. I've very little idea about how to create a custom view. I checked a lot of tutorials, but couldn't find a starting point. I've no images regarding the progressbar. I'm supposed to draw it. I tried overriding the ondraw method, but I was unable to get the exact look.

Here is the image : image

Thanks for your help

Darshan Bidkar
  • 515
  • 2
  • 6
  • 9

3 Answers3

2

First off, you will only need one image of your loading arcs as they are replicable.

http://developer.android.com/guide/topics/ui/custom-components.html

public class CustomView extends View 
{
public CustomView(Context context) 
{
    super(context);
}

protected void onDraw(Canvas canvas)
{
    canvas.drawBitmap(REFERENCETIBITMAPHERE, 0, 0, null);
}

@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
 {
    setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
 }

private int measureWidth(int measureSpec)
{
    int preferred = REFERENCETIBITMAPHERE.getWidth();
    return getMeasurement(measureSpec, preferred);
}

private int measureHeight(int measureSpec)
{
    int preferred = REFERENCETIBITMAPHERE.getHeight();
    return getMeasurement(measureSpec, preferred);
}

private int getMeasurement(int measureSpec, int preferred)
{
    int specSize = MeasureSpec.getSize(measureSpec);
    int measurement = 0;

    switch(MeasureSpec.getMode(measureSpec))
  {
    case MeasureSpec.EXACTLY:
        measurement = specSize;
        break;
    case MeasureSpec.AT_MOST:
        measurement = Math.min(preferred, specSize);
        break;
    default:
        measurement = preferred;
        break;
  }
    return measurement;
}
}

You will need to create your own method to receive some sort of value indicating the loading progress, and then redraw accordingly.

For example:

protected void onDraw(Canvas canvas)
{
    // Where loadProgress is an int of some sort.
    for(int i = 0; i < loadProgress; i++)
    {
        canvas.drawBitmap(REFERENCETIBITMAPHERE, REFERENCEBITMAPHERE.getWidth() * i, 0, null);
    }
}

I hope this helps. =)

Aelexe
  • 1,216
  • 3
  • 18
  • 27
1

pls try this.

private void showProgressDialog() {

    pDlg = new ProgressDialog(activity);
    pDlg.setMessage(processMessage);

    pDlg.setMax(100);
    pDlg.setProgressDrawable(c.getResources().getDrawable(R.drawable.my_progress_bar));
    pDlg.setCancelable(false);
    pDlg.show();

    }

your image = view.getResources().getDrawable(R.drawable.my_progress_bar)

KEYSAN
  • 885
  • 8
  • 23
0

You want to create your own progressbar, then you can override any view class, override the onDraw method and write it down your own code.

If you need some example then I will provide you.

Vishal Pawar
  • 4,324
  • 4
  • 28
  • 54