Android custom progress bar-horizontal progress bar with text (Text progress)

Source: Internet
Author: User

The default progress bar does not contain text progress prompts. to display the progress more intuitively, The progressbar control is customized to display the text progress:
That is to say, it is very powerful to add a text display progress bar (with % 100) to the progressbar,

Refer to here:Http://orgcent.com/android-text-progressbar/
I am not talking nonsense about the Code directly:

/***** @ Author lixiaodaoaaa * http://weibo.com/lixiaodaoaaa * http://t.qq.com/lixiaodaoaaa */public class textprogressbar extends progressbar {private string STR; private paint mpaint; Public textprogressbar (context) {super (context); inittext ();} public textprogressbar (context, attributeset attrs, int defstyle) {super (context, attrs, defstyle); inittext ();} public textprogressbar (context, attributeset attrs) {super (context, attrs); inittext () ;}@ overridepublic void setprogress (INT progress) {settext (Progress); super. setprogress (Progress) ;}@ overrideprotected synchronized void ondraw (canvas) {super. ondraw (canvas); rect = new rect (); this. mpaint. gettextbounds (this. STR, 0, this. str. length (), rect); int x = (getwidth ()/2)-rect. centerx (); // place the actual font in the center; int y = (getheight ()/2)-rect. centery (); // place the displayed font in the center; canvas. drawtext (this. STR, X, Y, this. mpaint);} // initialization, brush private void inittext () {This. mpaint = new paint (); this. mpaint. setantialias (true); // you can specify the value of this parameter. mpaint. setcolor (color. white);} // set the text content private void settext (INT progress) {int I = (INT) (Progress * 1.0f/This. getmax () * 100); this. STR = string. valueof (I) + "% ";}}

 

 

 


 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.