当前位置:   article > 正文

Note: day-4-23-2018 canvas绘制示意灯_java 使用canvas画小灯泡

java 使用canvas画小灯泡
   @Override
   public void onDraw(Canvas canvas) {
      Log.w(TAG, "onDraw(),i="+i);
      super.onDraw(canvas);
      for (int l = 0; l < i; l++) {
         canvas.drawRect(backgRect[l], paint(RED_BOTTOM));
         canvas.drawRect(topRect[l], paint(RED_TOP));
         canvas.drawRect(lineRect[l], paint(RED_LINE));
         Log.w(TAG,"make red"+l);
      }
      for (int l = i; l < 9; l++) {
         canvas.drawRect(backgRect[l], paint(DARK_BOTTOM));
         canvas.drawRect(topRect[l], paint(DARK_TOP));
         canvas.drawRect(lineRect[l], paint(DARK_LINE));
      }
   }

   @Override
   protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);
      for (int i = 0; i < 9; i++) {
         backgRect[i] = new Rect(getLeft() + (i + 1) * (getRight() - getLeft()) / 10 - 9, 0, getLeft() + (i + 1) * (getRight() - getLeft()) / 10 + 9, getBottom());
         lineRect[i] = new Rect(getLeft() + (i + 1) * (getRight() - getLeft()) / 10 - 9, 10, getLeft() + (i + 1) * (getRight() - getLeft()) / 10 + 9, 12);
         topRect[i] = new Rect(getLeft() + (i + 1) * (getRight() - getLeft()) / 10 - 9, 0, getLeft() + (i + 1) * (getRight() - getLeft()) / 10 + 9, 10);
      }
   }

   public void setLevel(int level) {
      Log.w(TAG, "level:" + level);
      if(i!=level){
         i = level;
         invalidate();
      }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/107374
推荐阅读
相关标签
  

闽ICP备14008679号