Ok I have decided to go with the arc drawing approach, so I have
extended the Progress bar class with my own. So if anyone thinks about
doing the same, here is my onDraw() method
protected synchronized void onDraw(Canvas canvas) {
int progress = this.getProgress();
int maxProgress = this.getMax();
//calc the progress to angles
float angleProgress = progress * 360 / maxProgress;
//create and set the arc paint
Paint arcPaint = new Paint();
arcPaint.setColor(0xff800000);
arcPaint.setAntiAlias(true);
arcPaint.setStyle(Style.FILL);
//get the drawing rect of your progress bar layout object.
//This way you can change the size in layout files (easier
support
for multiple screen size)
Rect arcRect = new Rect();
this.getDrawingRect(arcRect);
// Draw the Arc into that rect
canvas.drawArc(new RectF(arcRect), -90, angleProgress,true,
arcPaint);
}
Remember that in the layout xml file you define a ProgressBar element,
set all parameters, and then change it's name to package.classname of
your own progress bar class. Hope it helps somebody.
On 15 Maj, 20:39, Serdel <[email protected]> wrote:
> Thanks guys, I have tested all this and almost achieved what I want. I
> have change the code form Romain Guy a little bit so now I have:
>
> <item>
> <shape android:shape="oval">
> <gradient
> android:useLevel="true"
> android:type="sweep"
> android:startColor="#ff000000"
> android:endColor="#ffffffff" />
> </shape>
> </item>
>
> And this is almost what I want. I would like to change the eliminate
> the gradient factor so the circle that is 'unfolding' has the same
> colour all the time. If this is manageable then I guess I'm home :>
>
> On 14 Maj, 20:42, Dianne Hackborn <[email protected]> wrote:
>
> > Just set this as the drawable in a ProgressBar widget and control it with
> > that.
>
> > On Sat, May 14, 2011 at 5:43 AM,Serdel<[email protected]>wrote:
>
> > > That in deed is a nice approach. I wasn't aware that android has such
> > > a drawable. To abd this is more a 'ring' shape than a filled circle,
> > > but I guess a ring is also acceptable. But can you give me a hint how
> > > to control the 'progress' in the java code? So that I can i.e.
> > > increase it fluently in a timer or indicate a progress in downloading
> > > a file.
>
> > > On 13 Maj, 23:19, Romain Guy <[email protected]> wrote:
> > > > You don't need to do all this. All you need is a drawable that supports
> > > > levels. Android even provides a circle drawable that gets filled when
> > > > you
> > > > change the progress. Here's an example:
>
> > > > <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
> > > > <item
> > > android:drawable="@android:drawable/progress_circular_background" />
> > > > <item>
> > > > <shape android:shape="ring"
> > > > android:innerRadiusRatio="3.4"
> > > > android:thicknessRatio="6.0">
> > > > <gradient
> > > > android:useLevel="true"
> > > > android:type="sweep"
> > > > android:startColor="#ff000000"
> > > > android:endColor="#ffffffff" />
> > > > </shape>
> > > > </item>
> > > > <item>
> > > > <rotate
> > > > android:pivotX="50%" android:pivotY="50%"
> > > > android:fromDegrees="0" android:toDegrees="360"
> > > > android:drawable="@android:drawable/progress_particle" />
> > > > </item>
> > > > </layer-list>
>
> > > > On Fri, May 13, 2011 at 2:12 PM, Nicholas Johnson
> > > > <[email protected]>wrote:
>
> > > > > Here's what you can do:
>
> > > > > Extend the AbsSeekBar class<
> > >http://developer.android.com/reference/android/widget/AbsSeekBar.html>,
> > > > > and implement the onDraw method to your liking. You can capture the
> > > height
> > > > > and width of your custom view by capturing those values in the
> > > onSizeChanged
> > > > > method. By drawing your circle programatically you can easily make a
> > > > > progress circle that looks good at all resolutions. Also, you don't
> > > have to
> > > > > worry about different device resolutions, since you just need to
> > > control the
> > > > > size of the view in the layout.
>
> > > > > Or, you could extend the ProgressBar class and do the same thing.
>
> > > > > Nick
>
> > > > > --
> > > > > You received this message because you are subscribed to the Google
> > > > > Groups "Android Developers" group.
> > > > > To post to this group, send email to
> > > [email protected]
> > > > > To unsubscribe from this group, send email to
> > > > > [email protected]
> > > > > For more options, visit this group at
> > > > >http://groups.google.com/group/android-developers?hl=en
>
> > > > --
> > > > Romain Guy
> > > > Android framework engineer
> > > > [email protected]
>
> > > > Note: please don't send private questions to me, as I don't have time to
> > > > provide private support. All such questions should be posted on public
> > > > forums, where I and others can see and answer them
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en
>
> > --
> > Dianne Hackborn
> > Android framework engineer
> > [email protected]
>
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails. All such
> > questions should be posted on public forums, where I and others can see and
> > answer them.
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en