国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android progressbar實(shí)現(xiàn)帶底部指示器和文字的進(jìn)度條

2019-10-21 21:31:16
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例為大家分享了Android實(shí)現(xiàn)帶指示器和文字的進(jìn)度條,供大家參考,具體內(nèi)容如下

根據(jù)項(xiàng)目要求需要實(shí)現(xiàn)以下效果:

Android,progressbar,指示器,文字,進(jìn)度條

列出源碼:

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();   //畫(huà)指示器  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);   //寫(xiě)字  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);  }  //初始化,畫(huà)筆 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; }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 浦江县| 诸暨市| 湟中县| 应用必备| 桃源县| 云林县| 察雅县| 阳朔县| 延川县| 安远县| 吴川市| 大渡口区| 海伦市| 柘城县| 大竹县| 上饶县| 南宫市| 手机| 德庆县| 青川县| 东方市| 吴川市| 和田市| 乌恰县| 芦溪县| 高陵县| 龙井市| 噶尔县| 康平县| 罗田县| 邯郸市| 宜丰县| 安宁市| 华阴市| 西林县| 芜湖县| 乌鲁木齐县| 衡南县| 华池县| 海林市| 邹城市|