Android programming implements a progress bar effect similar to the circular ProgressBar

This article describes the implementation of progress bar effect similar to circular ProgressBar by Android programming. Share with you for your reference, as follows:

We want to implement a circular playback progress bar similar to that in Xiaomi sharing. The circular ProgressBar provided by Android rotates automatically by default, so it cannot be implemented. Therefore, we thought of using a custom view to achieve this effect.

First, let's take a look at the view defined by ourselves

By rewriting the OnDraw method of view, we judge the current playback position according to the good Fmax of farcnum, and then constantly refresh and change the view to achieve this effect. As for arc drawing, the drawarc method is adopted, and then the excess part is covered by drawing a circle inside it.

The following is the synchronization of mediaplayer and the view. The core code is as follows

Frontpv is the view defined by ourselves, the last handler sent is to call the invalidate method to refresh the view, and mpmediaplayers is the mediaplayer object defined by us. We update the farcnum in frontpv every second in the process and refresh to realize the animation effect of rotation.

For more Android related content, readers who are interested can view the topics on this site: introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solutions, summary of Android multimedia operation skills (audio, video, recording, etc.), summary of Android basic component usage, summary of Android view skills Android layout skills summary and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>