當前位置: 首頁>>代碼示例>>Java>>正文


Java Canvas.drawRect方法代碼示例

本文整理匯總了Java中android.graphics.Canvas.drawRect方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.drawRect方法的具體用法?Java Canvas.drawRect怎麽用?Java Canvas.drawRect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.graphics.Canvas的用法示例。


在下文中一共展示了Canvas.drawRect方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: drawLabelTextAndBackground

import android.graphics.Canvas; //導入方法依賴的package包/類
protected void drawLabelTextAndBackground(Canvas canvas, char[] labelBuffer, int startIndex, int numChars, int autoBackgroundColor) {
    float textX;
    float textY;
    if (this.isValueLabelBackgroundEnabled) {
        if (this.isValueLabelBackgroundAuto) {
            this.labelBackgroundPaint.setColor(autoBackgroundColor);
        }
        canvas.drawRect(this.labelBackgroundRect, this.labelBackgroundPaint);
        textX = this.labelBackgroundRect.left + ((float) this.labelMargin);
        textY = this.labelBackgroundRect.bottom - ((float) this.labelMargin);
    } else {
        textX = this.labelBackgroundRect.left;
        textY = this.labelBackgroundRect.bottom;
    }
    if (labelBuffer[startIndex] != '0') {
        canvas.drawText(labelBuffer, startIndex, numChars, textX, textY, this.labelPaint);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:19,代碼來源:AbstractChartRenderer.java

示例2: renderNoPage

import android.graphics.Canvas; //導入方法依賴的package包/類
private void renderNoPage(Bitmap bitmap, final RenderListener listener, Rect localVisRect, Rect globalVisRect)
{
	//  specify where to draw to and from
	mDrawBitmap = bitmap;
	mDrawSrcRect.set(globalVisRect);
	mDrawDstRect.set(localVisRect);

	//  make a rect representing the entire page in screen coordinates
	int[] locations = new int[2];
	getLocationOnScreen(locations);
	Rect pageRect = new Rect(locations[0], locations[1], locations[0] + getWidth(), locations[1] + getHeight());

	//  draw a yellow page with a red border containing the page number

	Paint p = new Paint();
	Canvas c = new Canvas(bitmap);
	p.setColor(Color.RED);
	p.setStyle(Paint.Style.FILL);
	c.drawRect(pageRect, p);

	Rect smaller = new Rect(pageRect);
	int inset = (int) (40 * mScale);
	smaller.inset(inset, inset);
	p.setColor(Color.YELLOW);
	p.setStyle(Paint.Style.FILL);
	c.drawRect(smaller, p);

	String s = "" + (mPageNum + 1);
	p.setColor(Color.BLACK);
	p.setTextSize(200.0f * mScale);
	c.drawText(s, pageRect.left + (90 * mScale), pageRect.top + (290 * mScale), p);

	invalidate();
	listener.progress(0);
}
 
開發者ID:ArtifexSoftware,項目名稱:mupdf-android-viewer-nui,代碼行數:36,代碼來源:DocPageView.java

示例3: drawBar

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void drawBar(Canvas barCanvas) {
	int width = barCanvas.getWidth();
	int height = barCanvas.getHeight();

	barCanvas.drawRect(0, 0, width, height, alphaPatternPaint);
	int l = Math.max(2, width / 256);
	for (int x = 0; x <= width; x += l) {
		float alpha = (float) x / (width - 1);
		barPaint.setColor(color);
		barPaint.setAlpha(Math.round(alpha * 255));
		barCanvas.drawRect(x, 0, x + l, height, barPaint);
	}
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:15,代碼來源:AlphaSlider.java

示例4: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas, Paint paint) {
    float rWidth=getWidth()/5;
    float rHeight=getHeight()/5;
    for (int i = 0; i < 2; i++) {
        canvas.save();
        canvas.translate(translateX[i], translateY[i]);
        canvas.rotate(degrees);
        canvas.scale(scaleFloat,scaleFloat);
        RectF rectF=new RectF(-rWidth/2,-rHeight/2,rWidth/2,rHeight/2);
        canvas.drawRect(rectF,paint);
        canvas.restore();
    }
}
 
開發者ID:zhouphenix,項目名稱:Multi-SwipeToRefreshLayout,代碼行數:15,代碼來源:CubeTransitionIndicator.java

示例5: drawOtherTopLeftRoundRect

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) {
  canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius,
      paint);
  canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius,
      paint);
  canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint);
}
 
開發者ID:open-android,項目名稱:Picasso-transformations,代碼行數:8,代碼來源:RoundedCornersTransformation.java

示例6: scaleTest02

import android.graphics.Canvas; //導入方法依賴的package包/類
private void scaleTest02(Canvas canvas) {
    canvas.translate(mWidth / 2, mHeight / 2);
    paint.setColor(Color.RED);
    Rect rect = new Rect(0, -400, 400, 0);
    canvas.drawRect(rect, paint);
    canvas.save();
    canvas.scale(0.5f, 0.5f, 200, 0);
    paint.setColor(Color.BLUE);
    canvas.drawRect(rect, paint);
    canvas.restore();
}
 
開發者ID:lixiaodaoaaa,項目名稱:ColumnAnimViewProject,代碼行數:12,代碼來源:CanvasTestView.java

示例7: drawLayerBounds

import android.graphics.Canvas; //導入方法依賴的package包/類
private static void drawLayerBounds(@Nonnull Canvas canvas,
                                    @Nonnull Rect bounds,
                                    int sectionNumber,
                                    @Nonnull Paint fillPaint,
                                    @Nonnull Paint outlinePaint,
                                    @Nonnull Paint textPaint) {
    Rect startRect = new Rect(bounds.left + 1, bounds.top + 1, bounds.right - 1, bounds.bottom - 1);
    canvas.drawRect(startRect, fillPaint);
    canvas.drawRect(startRect, outlinePaint);
    canvas.drawText("" + sectionNumber, bounds.left + 6, bounds.top + 21, textPaint);
}
 
開發者ID:shazam,項目名稱:reflow-animator,代碼行數:12,代碼來源:ReflowTextAnimatorHelper.java

示例8: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int width = this.getWidth();
    int height = this.getHeight();

    double barHeight = 0.0;
    if(mPercent > 0){
        barHeight = mPercent / 100 * height;
    }

    mPaint.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
    canvas.drawRect(0, height-(float)barHeight, width, height, mPaint);
}
 
開發者ID:hamatani63,項目名稱:Waffle,代碼行數:16,代碼來源:BarGraphView.java

示例9: drawVertical

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawVertical(Canvas c, RecyclerView parent) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    int top, bottom;

    View child = null;
    RecyclerView.LayoutParams params = null;
    for (int i = 0; i < childCount; i++) {
        child = parent.getChildAt(i);
        params = (RecyclerView.LayoutParams) child.getLayoutParams();

        if (i == 0) {
            //如果是第一個元素,就繪製上邊線
            //child.getTop() - params.topMargin 得到的是child的y起點坐標,需要在該y坐標之前繪製寬度為mWidth的線,所以需要減mWidth
            top = child.getTop() - params.topMargin - mWidthPx;
            bottom = top + mWidthPx;
            //繪製上邊線
            c.drawRect(left, top, right, bottom, mPaint);
        }

        top = child.getBottom() + params.bottomMargin;
        bottom = top + mWidthPx;

        c.drawRect(left, top, right, bottom, mPaint);
    }
}
 
開發者ID:yhyzgn,項目名稱:Widgets,代碼行數:29,代碼來源:RvDivider.java

示例10: draw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
    if (emojiBmp[info.page][info.page2] == null) {
        if (loadingEmoji[info.page][info.page2]) {
            return;
        }
        loadingEmoji[info.page][info.page2] = true;
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                loadEmoji(info.page, info.page2);
                loadingEmoji[info.page][info.page2] = false;
            }
        });
        canvas.drawRect(getBounds(), placeholderPaint);
        return;
    }

    Rect b;
    if (fullSize) {
        b = getDrawRect();
    } else {
        b = getBounds();
    }

    //if (!canvas.quickReject(b.left, b.top, b.right, b.bottom, Canvas.EdgeType.AA)) {
        canvas.drawBitmap(emojiBmp[info.page][info.page2], info.rect, b, paint);
    //}
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:30,代碼來源:Emoji.java

示例11: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    if (mShape == SHAPE_RECT) {
        mPaint.setColor(mBgColor);
        canvas.drawRect(mBackRect, mPaint);
        mPaint.setAlpha(mAlpha);
        canvas.drawRect(mBackRect, mPaint);
        mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
                + getMeasuredWidth() / 2 - RIM_SIZE, getMeasuredHeight()
                - RIM_SIZE);
        mPaint.setColor(mFgColor);
        canvas.drawRect(mFrontRect, mPaint);

        if (mClippableView != null) {
            ViewCompat.setClipBounds(mClippableView, mFrontRect);
        }
    } else {
        // draw circle
        int radius;
        radius = mBackRect.height() / 2 - RIM_SIZE;
        mPaint.setColor(mBgColor);
        mBackCircleRect.set(mBackRect);
        canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
        mPaint.setColor(mFgColor);
        mPaint.setAlpha(mAlpha);
        canvas.drawRoundRect(mBackCircleRect, radius, radius, mPaint);
        mFrontRect.set(mFrontRectLeft, RIM_SIZE, mFrontRectLeft
                + mBackRect.height() - 2 * RIM_SIZE, mBackRect.height()
                - RIM_SIZE);
        mFrontCircleRect.set(mFrontRect);
        mPaint.setColor(Color.WHITE);
        canvas.drawRoundRect(mFrontCircleRect, radius, radius, mPaint);
    }
}
 
開發者ID:TechIsFun,項目名稱:SlidingSwitch,代碼行數:35,代碼來源:SlidingSwitchBase.java

示例12: drawUnderline

import android.graphics.Canvas; //導入方法依賴的package包/類
private void drawUnderline(Canvas canvas, int left, int right, int height) {
  if (bottomBorderThickness <= 0) {
    return;
  }
  // Thin underline along the entire bottom edge
  borderPaint.setColor(bottomBorderColor);
  canvas.drawRect(left, height - bottomBorderThickness, right, height, borderPaint);
}
 
開發者ID:huashengzzz,項目名稱:SmartChart,代碼行數:9,代碼來源:SmartTabStrip.java

示例13: addReflection

import android.graphics.Canvas; //導入方法依賴的package包/類
/**
 * 添加倒影
 *
 * @param src              源圖片的
 * @param reflectionHeight 倒影高度
 * @param recycle          是否回收
 * @return 帶倒影圖片
 */
public static Bitmap addReflection(Bitmap src, int reflectionHeight, boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    // 原圖與倒影之間的間距
    final int REFLECTION_GAP = 0;
    int srcWidth = src.getWidth();
    int srcHeight = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionBitmap = Bitmap.createBitmap(src, 0, srcHeight - reflectionHeight,
            srcWidth, reflectionHeight, matrix, false);
    Bitmap ret = Bitmap.createBitmap(srcWidth, srcHeight + reflectionHeight, src.getConfig());
    Canvas canvas = new Canvas(ret);
    canvas.drawBitmap(src, 0, 0, null);
    canvas.drawBitmap(reflectionBitmap, 0, srcHeight + REFLECTION_GAP, null);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    LinearGradient shader = new LinearGradient(0, srcHeight,
            0, ret.getHeight() + REFLECTION_GAP,
            0x70FFFFFF, 0x00FFFFFF, Shader.TileMode.MIRROR);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    canvas.drawRect(0, srcHeight + REFLECTION_GAP,
            srcWidth, ret.getHeight(), paint);
    if (!reflectionBitmap.isRecycled()) reflectionBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:36,代碼來源:ImageUtils.java

示例14: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (isInEditMode() || tabCount == 0) {
		return;
	}

	final int height = getHeight();

	// draw indicator line

	rectPaint.setColor(indicatorColor);

	// default: line below current tab
	View currentTab = tabsContainer.getChildAt(currentPosition);

	float textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
	int indicatorSpac = (int) ((TextView) currentTab).getWidth();

	float lineLeft = currentTab.getLeft();
	float lineRight = currentTab.getRight();

	// if there is an offset, start interpolating left and right coordinates
	// between current and next tab
	if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

		View nextTab = tabsContainer.getChildAt(currentPosition + 1);
		textViewContentWidth = getTextViewContentWidth((TextView) currentTab);
		indicatorSpac = (int) ((TextView) currentTab).getWidth();

		final float nextTabLeft = nextTab.getLeft();
		final float nextTabRight = nextTab.getRight();

		lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset)
				* lineLeft);
		lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset)
				* lineRight);
	}
	if (indicatorWrapContent) { 
		canvas.drawRect(lineLeft - wrapAddWidth+getPaddingLeft()
				+ (indicatorSpac - textViewContentWidth) / 2, height
				- indicatorHeight,
				lineRight+getPaddingLeft() - (indicatorSpac - textViewContentWidth) / 2
						+ wrapAddWidth, height, rectPaint);

	} else {
		canvas.drawRect(lineLeft+getPaddingLeft(), height - indicatorHeight, lineRight+getPaddingLeft(),
				height, rectPaint);
	}
	// draw underline

	rectPaint.setColor(underlineColor);
	canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(),
			height, rectPaint);

	// draw divider

	dividerPaint.setColor(dividerColor);
	for (int i = 0; i < tabCount - 1; i++) {
		View tab = tabsContainer.getChildAt(i);
		canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(),
				height - dividerPadding, dividerPaint);
	}
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:66,代碼來源:PagerSlidingTabStrip.java

示例15: onDraw

import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);

	if (isInEditMode() || tabCount == 0) {
		return;
	}

	final int height = getHeight();

	// draw indicator line

	rectPaint.setColor(indicatorColor);

	// default: line below current tab
	View currentTab = tabsContainer.getChildAt(currentPosition);
	float lineLeft = currentTab.getLeft();
	float lineRight = currentTab.getRight();

	// if there is an offset, start interpolating left and right coordinates between current and next tab
	if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

		View nextTab = tabsContainer.getChildAt(currentPosition + 1);
		final float nextTabLeft = nextTab.getLeft();
		final float nextTabRight = nextTab.getRight();

		lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
		lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
	}

	canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

	// draw underline

	rectPaint.setColor(underlineColor);
	canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

	// draw divider

	dividerPaint.setColor(dividerColor);
	for (int i = 0; i < tabCount - 1; i++) {
		View tab = tabsContainer.getChildAt(i);
		canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
	}
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:46,代碼來源:PagerSlidingTabStrip.java


注:本文中的android.graphics.Canvas.drawRect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。