@Override
 protected void onDraw(Canvas canvas) {
   if (getContext().getResources().getConfiguration().orientation
       == Configuration.ORIENTATION_LANDSCAPE) {
     // use topY
     if (indicatorBitmap != null) {
       // canvas.drawBitmap(indicatorBitmap, 0, topY, null);
       ninePatch.draw(canvas, rectD);
     }
   } else {
     // use topX
     if (indicatorBitmap != null) {
       ninePatch.draw(canvas, rectD);
       // canvas.drawBitmap(indicatorBitmap, new Rect(0,0,indicatorBitmap.getWidth(),
       // indicatorBitmap.getHeight()), new Rect(leftX, 0, leftX+lp.width, lp.height),  null);
     }
   }
 }
  @Override
  public void draw(Canvas canvas) {
    final Rect bounds = getBounds();

    final boolean clearColorFilter;
    if (mTintFilter != null && getPaint().getColorFilter() == null) {
      mPaint.setColorFilter(mTintFilter);
      clearColorFilter = true;
    } else {
      clearColorFilter = false;
    }

    final boolean needsMirroring = needsMirroring();
    if (needsMirroring) {
      // Mirror the 9patch
      canvas.translate(bounds.right - bounds.left, 0);
      canvas.scale(-1.0f, 1.0f);
    }

    final int restoreAlpha;
    if (mNinePatchState.mBaseAlpha != 1.0f) {
      restoreAlpha = mPaint.getAlpha();
      mPaint.setAlpha((int) (restoreAlpha * mNinePatchState.mBaseAlpha + 0.5f));
    } else {
      restoreAlpha = -1;
    }

    mNinePatch.draw(canvas, bounds, mPaint);

    if (clearColorFilter) {
      mPaint.setColorFilter(null);
    }

    if (restoreAlpha >= 0) {
      mPaint.setAlpha(restoreAlpha);
    }
  }
예제 #3
0
 public void drawNinepath(Canvas c, Rect r1) {
   NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
   patch.draw(c, r1);
 }
예제 #4
0
 /**
  * 手动绘制.9.png图片
  *
  * @param canvas
  * @param resId
  * @param rect
  */
 private void drawNinepath(Canvas canvas, int resId, Rect rect) {
   Bitmap bmp = BitmapFactory.decodeResource(getResources(), resId);
   NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
   patch.draw(canvas, rect);
 }