In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use progressbar to achieve with bottom indicator and text progress bar in Android". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to use progressbar in Android with bottom indicator and text progress bar"!
List the source code:
Public class TextProgressBar extends LinearLayout {String text; Paint mPaint; private Rect textRect; private Bitmap bitmap; private ProgressBar progressBar; int progress; int proWidth, proHeight; public TextProgressBar (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); initText (context);} public TextProgressBar (Context context) {super (context); initText (context);} public TextProgressBar (Context context, AttributeSet attrs) {super (context, attrs); initText (context) } @ Override protected synchronized void onDraw (Canvas canvas) {super.onDraw (canvas); progress = progressBar.getProgress (); if (progress = = 0 | progress = = progressBar.getMax () return; this.mPaint.getTextBounds (this.text, 0, this.text.length (), textRect); proWidth = progressBar.getWidth (); proHeight = progressBar.getHeight () / / drawing indicator int bitmapx = (int) (progressBar.getLeft () + proWidth * ((progress * 1f) / progressBar.getMax ())-bitmap.getWidth () / 2; int bitmapy = proHeight + bitmap.getHeight () / 2; if (bitmapx
< 0) bitmapx = progressBar.getLeft(); if(bitmapx >ProgressBar.getRight ()-bitmap.getWidth () bitmapx = progressBar.getRight ()-bitmap.getWidth (); canvas.drawBitmap (bitmap, bitmapx, bitmapy, mPaint); / / write int tvx = (int) (progressBar.getLeft () + proWidth * ((progress * 1f) / progressBar.getMax ())-textRect.centerX (); int tvy = proHeight + bitmap.getHeight () * 2 + 4; if (tvx)
< 0) tvx = progressBar.getLeft(); if(tvx >= progressBar.getRight ()-textRect.width () tvx = progressBar.getRight ()-textRect.width (); canvas.drawText (this.text, tvx, tvy + bitmap.getHeight (), this.mPaint);} / / initialize, brush private void initText (Context context) {View inflate = View.inflate (context, R.layout.textprogressbar, this); progressBar = (ProgressBar) inflate.findViewById (R.id.progressbar1); progressBar.setProgress (50); setWillNotDraw (false); this.mPaint = new Paint () This.mPaint.setColor (getResources (). GetColor (R.color.red)); this.mPaint.setTextSize (20); textRect = new Rect (); text = "0"; bitmap = BitmapFactory.decodeResource (context.getResources (), R.mipmap.progress_top);} public void setProgress (int progress) {progressBar.setProgress (progress);} public void setText (String str) {text = str }} at this point, I believe you have a deeper understanding of "how to use progressbar to achieve with a bottom indicator and text progress bar in Android". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.