本文整理汇总了Java中android.graphics.Canvas.drawArc方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.drawArc方法的具体用法?Java Canvas.drawArc怎么用?Java Canvas.drawArc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.drawArc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
float eatRightX = mPadding + eatErWidth + eatErPositionX;
RectF rectF = new RectF(mPadding + eatErPositionX, mHigh / 2 - eatErWidth / 2, eatRightX, mHigh / 2 + eatErWidth / 2);
canvas.drawArc(rectF, eatErStartAngle, eatErEndAngle
, true, mPaint);
canvas.drawCircle(mPadding + eatErPositionX + eatErWidth / 2,
mHigh / 2 - eatErWidth / 4,
beansWidth / 2, mPaintEye);
int beansCount = (int) ((mWidth - mPadding * 2 - eatErWidth) / beansWidth / 2);
for (int i = 0; i < beansCount; i++) {
float x = beansCount * i + beansWidth / 2 + mPadding + eatErWidth;
if (x > eatRightX) {
canvas.drawCircle(x,
mHigh / 2, beansWidth / 2, mPaint);
}
}
}
示例2: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* Draw the progress spinner
*/
public void draw(Canvas c, Rect bounds) {
final RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
arcBounds.inset(mStrokeInset, mStrokeInset);
final float startAngle = (mStartTrim + mRotation) * 360;
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;
mPaint.setColor(mColors[mColorIndex]);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
drawTriangle(c, startAngle, sweepAngle, bounds);
if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
mCirclePaint);
}
}
示例3: drawOuter
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawOuter(Canvas canvas, int viewWidth) {
if (mShowOuter) {
float outerR = mBollRadius + mOuterPaint.getStrokeWidth() * 2;
mRefreshStart += mOuterIsStart ? 3 : 10;
mRefreshStop += mOuterIsStart ? 10 : 3;
mRefreshStart = mRefreshStart % 360;
mRefreshStop = mRefreshStop % 360;
int swipe = mRefreshStop - mRefreshStart;
swipe = swipe < 0 ? swipe + 360 : swipe;
canvas.drawArc(new RectF(viewWidth / 2 - outerR, mBollY - outerR, viewWidth / 2 + outerR, mBollY + outerR),
mRefreshStart, swipe, false, mOuterPaint);
if (swipe >= TARGET_DEGREE) {
mOuterIsStart = false;
} else if (swipe <= 10) {
mOuterIsStart = true;
}
invalidate();
}
}
示例4: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int w = getMeasuredWidth()/num-10;
mPath.setStyle(Paint.Style.FILL);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, r, mPath);
canvas.save();
mPath.setStyle(Paint.Style.STROKE);//设置为空心
mPath.setStrokeWidth(6);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, r + 15, mPath);
canvas.restore();
mPantR.setStyle(Paint.Style.FILL);
RectF oval = new RectF(getMeasuredWidth()/2-r, getMeasuredHeight()/2-r, getMeasuredWidth()/2+r, getMeasuredHeight()/2+r);// 设置个新的长方形,扫描测量
canvas.drawArc(oval, stratAngle, endAngle, true, mPantR);
canvas.save();
mPantR.setStrokeWidth(6);
mPantR.setStyle(Paint.Style.STROKE);
RectF oval2 = new RectF(getMeasuredWidth()/2-r-outCir_value, getMeasuredHeight()/2-r-outCir_value, getMeasuredWidth()/2+r+outCir_value, getMeasuredHeight()/2+r+outCir_value);// 设置个新的长方形,扫描测量
canvas.drawArc(oval2, stratAngle, endAngle, false, mPantR);
canvas.restore();
}
示例5: drawPacman
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawPacman(Canvas canvas,Paint paint){
float x=getWidth()/2;
float y=getHeight()/2;
canvas.save();
canvas.translate(x, y);
canvas.rotate(degrees1);
paint.setAlpha(255);
RectF rectF1=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
canvas.drawArc(rectF1, 0, 270, true, paint);
canvas.restore();
canvas.save();
canvas.translate(x, y);
canvas.rotate(degrees2);
paint.setAlpha(255);
RectF rectF2=new RectF(-x/1.7f,-y/1.7f,x/1.7f,y/1.7f);
canvas.drawArc(rectF2,90,270,true,paint);
canvas.restore();
}
示例6: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* Draw the progress spinner
*/
public void draw(Canvas c, Rect bounds) {
final RectF arcBounds = mTempBounds;
arcBounds.set(bounds);
arcBounds.inset(mStrokeInset, mStrokeInset);
final float startAngle = (mStartTrim + mRotation) * 360;
final float endAngle = (mEndTrim + mRotation) * 360;
float sweepAngle = endAngle - startAngle;
mPaint.setColor(mColors[mColorIndex]);
c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
drawTriangle(c, startAngle, sweepAngle, bounds);
if (mAlpha < 255) {
mCirclePaint.setColor(mBackgroundColor);
mCirclePaint.setAlpha(255 - mAlpha);
c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2,
mCirclePaint);
}
}
示例7: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
if(!mClockwise) {
canvas.scale(-1, 1, mArcRect.centerX(), mArcRect.centerY() );
}
// Draw the arcs
final int arcStart = mStartAngle + mAngleOffset + mRotation;
final int arcSweep = mSweepAngle;
canvas.drawArc(mArcRect, arcStart, arcSweep, false, mArcPaint);
canvas.drawArc(mArcRect, arcStart, mProgressSweep, false,
mProgressPaint);
if(mEnabled) {
// Draw the thumb nail
canvas.translate(mTranslateX - mThumbXPos, mTranslateY - mThumbYPos);
mThumb.draw(canvas);
}
}
示例8: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
int halfWidth = getWidth() / 2;
int halfHeight = getHeight() /2;
int radius = halfWidth < halfHeight ? halfWidth : halfHeight;
float halfStrokeWidth = mStrokeWidth / 2;
// 设置画笔
mPaint.setColor(mBackgroundColor);
mPaint.setDither(true);
mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setStyle(Paint.Style.STROKE); //设置图形为空心
// 画背景
canvas.drawCircle(halfWidth, halfHeight, radius - halfStrokeWidth, mPaint);
// 画当前进度的圆环
mPaint.setColor(mPrimaryColor); // 改变画笔颜色
mRectF.top = halfHeight - radius + halfStrokeWidth;
mRectF.bottom = halfHeight + radius - halfStrokeWidth;
mRectF.left = halfWidth - radius + halfStrokeWidth;
mRectF.right = halfWidth + radius - halfStrokeWidth;
canvas.drawArc(mRectF, -90, getRateOfProgress() * 360, false, mPaint);
canvas.save();
}
示例9: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, circleLength1, mPaint1);
canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, circleLength2, mPaint2);
if (flag == 1) {
//FIXME: android4.x设备没有此api
canvas.drawArc(10, 10, getMeasuredWidth() - 10, getMeasuredHeight() - 10, -90, sweepAngle, false, mPaint3);
}
}
示例10: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
//获取view的边界
getDrawingRect(bounds);
int size = bounds.height() > bounds.width() ? bounds.width() : bounds.height();
float outerRadius = size / 2;
//画内部背景
int circleColor = inCircleColors.getColorForState(getDrawableState(), 0);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(circleColor);
canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth, mPaint);
//画边框圆
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(outLineWidth);
mPaint.setColor(outLineColor);
canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth / 2, mPaint);
//画字
Paint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
float textY = bounds.centerY() - (paint.descent() + paint.ascent()) / 2;
canvas.drawText(getText().toString(), bounds.centerX(), textY, paint);
//画进度条
mPaint.setColor(progressLineColor);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(progressLineWidth);
mPaint.setStrokeCap(Paint.Cap.ROUND);
int deleteWidth = progressLineWidth + outLineWidth;
mArcRect.set(bounds.left + deleteWidth / 2, bounds.top + deleteWidth / 2, bounds.right - deleteWidth / 2, bounds.bottom - deleteWidth / 2);
canvas.drawArc(mArcRect, 0, 360 * progress / 100, false, mPaint);
}
示例11: onDraw
import android.graphics.Canvas; //导入方法依赖的package包/类
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRoundRect(mRoundRect, mHeight / 2, mHeight / 2, mBackgroundPaint);
canvas.drawArc(mArcRect, -90f, 360, true, mArcDarkPaint);
canvas.drawArc(mArcRect, -90f - 360 * (1 - getProgressRate()), 360 * (1 - getProgressRate()), true, mArcLightPaint);
if (isDark()) {
canvas.drawBitmap(mLightningDarkBitmap, mWidth - mARCWidth - UIUtils.dip2fpx(22), mARCWidth, null);
} else {
canvas.drawBitmap(mLightningBitmap, mWidth - mARCWidth - UIUtils.dip2fpx(22), mARCWidth, null);
}
}
示例12: drawCircle
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawCircle(Canvas canvas) {
initDrawStrokeCirclePaint();
canvas.drawArc(this.mRectF, 202.0f, this.mSweepAngle, false, this.mPaint);
initDrawAlphaStrokeCirclePaint();
canvas.drawArc(this.mRectF, 202.0f, this.mSweepAngle - 360.0f, false, this.mPaint);
initDrawInnerCirclePaint();
canvas.drawArc(this.mInnerRectF, 0.0f, 360.0f, false, this.mPaint);
}
示例13: draw
import android.graphics.Canvas; //导入方法依赖的package包/类
void draw(Canvas canvas) {
canvas.save();
canvas.rotate(-90, canvas.getWidth() / 2, canvas.getHeight() / 2);
canvas.drawArc(boundingBox, 0, 360, false, paint);
canvas.drawLines(marker, markerPaint);
canvas.restore();
}
示例14: drawProgress
import android.graphics.Canvas; //导入方法依赖的package包/类
/**
* 绘制进度条
*/
private void drawProgress(Canvas canvas) {
//绘制进度 根据设置的样式进行绘制
paint.setStrokeWidth(ringWidth);
paint.setColor(ringProgressColor);
//Stroke样式
RectF strokeOval = new RectF(centre - radius, centre - radius, centre + radius,
centre + radius);
//FIll样式
RectF fillOval = new RectF(centre - radius + ringWidth + padding,
centre - radius + ringWidth + padding, centre + radius - ringWidth - padding,
centre + radius - ringWidth - padding);
switch (style) {
case STROKE: {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
canvas.drawArc(strokeOval, -90, 360 * progress / max, false, paint);
break;
}
case FILL: {
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
if (progress != 0) {
canvas.drawArc(fillOval, -90, 360 * progress / max, true, paint);
}
break;
}
}
}
示例15: drawProgress
import android.graphics.Canvas; //导入方法依赖的package包/类
private void drawProgress(Canvas canvas) {
if (mCurrentProgress >= TOTAL_PROGRESS) {
mCurrentProgress = TOTAL_PROGRESS;
}
// 获取当前进度位置
mCurrentProgressPosition = mProgressWidth * mCurrentProgress / TOTAL_PROGRESS;
// 当进度条在圆弧内
if (mCurrentProgressPosition <= mArcRadius) {
//单边角度
int angle = (int) Math.toDegrees(Math.acos((mArcRadius - mCurrentProgressPosition) /
(float) mArcRadius));
//起始位置
int startAngle = 180 - angle;
//扫过的角度
int sweepAngle = 2 * angle;
// canvas.drawRect(mArcRectF, mOrangePaint);
canvas.drawArc(mArcRectF, startAngle, sweepAngle, false, mOrangePaint);
} else {
canvas.drawArc(mArcRectF, 90, 180, false, mOrangePaint);
mOrangeRectF.left = mArcRightLocation;
mOrangeRectF.right = mCurrentProgressPosition;
canvas.drawRect(mOrangeRectF, mOrangePaint);
}
}