简体   繁体   中英

Android ProgressBar in my View

I am trying to place a loading spinner into my canvas. In the constructor:

this.progressBar = new ProgressBar(context, null, Resource.Attribute.progressBarStyle);

And in the OnDraw :

protected override void OnDraw(Canvas canvas)
{
    base.OnDraw(canvas);

    // other code to draw other stuff...

    this.progressBar.Draw(canvas);
}

It is not appearing. Am I missing something? I checked the Width property and it is 0 while debugging, but I still don't know how to fix it.

My class extends View

You need to extend you class from ViewGroup or any layout (eg FrameLayout), then during initialization you need to call addView methods with your progress bar.

If you extending simple ViewGroup that additionally you need to override onMeasure and onLayout methods for providing computing size of progress widget and placing it on view group accordingly.

Here is a tutorial for Xamarin users for with more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM