Android进度条

FlyPanda_若曦 2017-01-06 11:12:39

有没有这样的进度条 或者怎么在进度条1/4 2/4 3/4处画线
...全文
384 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ink_s 2017-01-10
  • 打赏
  • 举报
回复
下载地址 把里面进度条的 onDraw 修改下 改成下面的样子
@Override
   protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      mPaint = new Paint();
      mPaint.setAntiAlias(true);
      int round = mHeight/2;
      System.out.println("max="+maxCount + "  current="+currentCount);
      mPaint.setColor(Color.rgb(71, 76, 80));
      RectF rectBg = new RectF(0, 0, mWidth, mHeight);
      canvas.drawRoundRect(rectBg, round, round, mPaint);
      mPaint.setColor(Color.BLACK);
      RectF rectBlackBg = new RectF(2, 2, mWidth-2, mHeight-2);
      canvas.drawRoundRect(rectBlackBg, round, round, mPaint);
      
      float section = currentCount/maxCount;
      RectF rectProgressBg = new RectF(3, 3, (mWidth-3)*section, mHeight-3);
      mPaint.setColor(SECTION_COLORS[0]);
      canvas.drawRoundRect(rectProgressBg, round, round, mPaint);

      if(section <= 0.23f/1.0f){

      }
      else if(section > 0.23f/1.0f & section <= 0.48f/1.0f){
            mPaint.setColor(SECTION_COLORS[1]);
            canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
      }
      else if(section > 0.48f/1.0f & section <= 0.73f/1.0f){
         mPaint.setColor(SECTION_COLORS[1]);
         canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
         mPaint.setColor(SECTION_COLORS[1]);
         canvas.drawRect(3+(mWidth-3)*0.48f, 3, (mWidth-3)*0.52f, mHeight-3,mPaint);
      }
      else if(section > 0.73f/1.0f){
         mPaint.setColor(SECTION_COLORS[1]);
         canvas.drawRect(3+(mWidth-3)*0.23f, 3, (mWidth-3)*0.27f, mHeight-3,mPaint);
         mPaint.setColor(SECTION_COLORS[1]);
         canvas.drawRect(3+(mWidth-3)*0.48f, 3, (mWidth-3)*0.52f, mHeight-3,mPaint);
         mPaint.setColor(SECTION_COLORS[1]);
         canvas.drawRect(3+(mWidth-3)*0.73f, 3, (mWidth-3)*0.77f, mHeight-3,mPaint);
      }


//    else{
//       int count = (section <= 1.0f/3.0f*2 ) ? 2 : 3;
//       int[] colors = new int[count];
//       System.arraycopy(SECTION_COLORS, 0, colors, 0, count);
//       float[] positions = new float[count];
//       if(count == 2){
//          positions[0] = 0.0f;
//          positions[1] = 1.0f-positions[0];
//       }else{
//          positions[0] = 0.0f;
//          positions[1] = (maxCount/3)/currentCount;
//          positions[2] = 1.0f-positions[0]*2;
//       }
//       positions[positions.length-1] = 1.0f;
//       LinearGradient shader = new LinearGradient(3, 3, (mWidth-3)*section, mHeight-3, colors,null, Shader.TileMode.MIRROR);
//       mPaint.setShader(shader);
//    }
//    canvas.drawRoundRect(rectProgressBg, round, round, mPaint);
   }

ink_s 2017-01-10
  • 打赏
  • 举报
回复


差不多效果吧 网上找的自定义进度条修改了下 ,好好改下效果更好。
FlyPanda_若曦 2017-01-10
  • 打赏
  • 举报
回复
引用 5 楼 Chen_xiaobao 的回复:
这样应该可以,分成4分 int length = 100; //获取文件大小 pBar.setMax(length); //设置进度条的总长度 FileOutputStream fileOutputStream = null; if (is != null) { fileOutputStream = new FileOutputStream(file); byte[] buf = new byte[1024000]; int ch = -1; int process = 0; while ((ch = is.read(buf)) != -1) { fileOutputStream.write(buf, 0, ch); process += ch; if (process < 100) pBar.setProgress(process); //这里就是关键的实时更新进度了! } }
没看懂这是干嘛的
FlyPanda_若曦 2017-01-10
  • 打赏
  • 举报
回复
[quote=引用 3 楼 SDDDLLL 的回复:] 其实可以这样,自定义一个控件继承progressbar,然后在这个控件的4 分之一处画一个图形即可[/quo 那前面的不就被覆盖了吗
志尊宝 2017-01-09
  • 打赏
  • 举报
回复
这样应该可以,分成4分 int length = 100; //获取文件大小 pBar.setMax(length); //设置进度条的总长度 FileOutputStream fileOutputStream = null; if (is != null) { fileOutputStream = new FileOutputStream(file); byte[] buf = new byte[1024000]; int ch = -1; int process = 0; while ((ch = is.read(buf)) != -1) { fileOutputStream.write(buf, 0, ch); process += ch; if (process < 100) pBar.setProgress(process); //这里就是关键的实时更新进度了! } }
愚公要移山 2017-01-07
  • 打赏
  • 举报
回复
其实可以这样,自定义一个控件继承progressbar,然后在这个控件的4 分之一处画一个图形即可
哎,真难 2017-01-06
  • 打赏
  • 举报
回复
自定义progress咯,挺简单的,在ondraw的时候绘制就行
developerzjy 2017-01-06
  • 打赏
  • 举报
回复
自定义view画个进度条 或者取巧的方法,把进度条放在一个viewgroup里面,判断符合一定的条件的时候在viewgroup里面的适当位置addview()

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧