在Android的弧形的边缘添加了一圈? [英] add a circle at the edge of arc android?

查看:305
本文介绍了在Android的弧形的边缘添加了一圈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在弧边缘添加小圈。结果
它应该是还与时钟方向圆弧边缘移动。结果,
现在我成功地使用动画改变后掠角的弧线。结果
和黑点的剩余量。

下面是getView的code和动画类

  --- init方法和实施构造---- mRectF =新RectF(mWidth / 2  -  360,mHeight / 2  -  360,mWidth / 2 + 360,mHeight / 2 + 360);@覆盖
保护无效的onDraw(帆布油画){
    super.onDraw(画布);
    //画出圆圈背景
    mPaint.setColor(getResources()的getColor(R.color.timer_background_color));
    canvas.drawCircle(mWidth / 2,mHeight / 2,360,mPaint);    mPaint.setColor(getResources()的getColor(R.color.actionbar_back_color));
    canvas.drawArc(mRectF,mStartAnagle,mSweepAngle,假的,mPaint);
}公共类TimerAnimation扩展动画{    公共TimerAnimation(浮动startAngle开始,浮sweepAngle,持续时间长){
        mStartAnagle = startAngle开始;
        mSweepAngle = sweepAngle;
        setDuration(持续时间);
        setRepeatCount(Animation.INFINITE);
        setInterpolator(新LinearInterpolator());
    }    @覆盖
    保护无效applyTransformation(浮动interpolatedTime,变换T){
        如果(!isComplete){
            mSweepAngle = mSweepAngle + 6;
            如果(mSweepAngle> = 360){
                isComplete = TRUE;
                mSweepAngle = 360;
            }
        }其他{
            mStartAnagle = mStartAnagle + 6;
            mSweepAngle = mSweepAngle - 6;
            如果(mStartAnagle> = 360)
                mStartAnagle = 0;
            如果(mStartAnagle == 270 || mSweepAngle&下; = 0){
                isComplete = FALSE;
                mSweepAngle = 0;
            }
        }
        无效();
    }
}


解决方案

也许你应该使用路径

 路径path =新路径();
//设置路径,以(0,0)的开始位置。
path.moveTo(0,0);
path.arcTo(...); //这里绘制弧形
path.circleTo(); //此处画小圈弧处的结束

另外,也许你应该<一个href=\"http://stackoverflow.com/questions/12882903/calculate-arc-center-point-knowing-its-start-and-end-degrees\">calc圆弧的终点位置并用作小圆圈的中心。

how to add small circle at the edge of arc.
and it should be also move with arc edge in the clock direction.
right now i am successfully animate the arc using changing the sweep angle.
and black dot is remaining.

below is the code of getView and animation class

--- init method and implement constructor ----

 mRectF = new RectF(mWidth / 2 - 360, mHeight / 2 - 360, mWidth / 2 + 360, mHeight / 2 + 360);

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    //draw circle background
    mPaint.setColor(getResources().getColor(R.color.timer_background_color));
    canvas.drawCircle(mWidth / 2, mHeight / 2, 360, mPaint);

    mPaint.setColor(getResources().getColor(R.color.actionbar_back_color));
    canvas.drawArc(mRectF, mStartAnagle, mSweepAngle, false, mPaint);
}

public class TimerAnimation extends Animation{

    public TimerAnimation (float startAngle, float sweepAngle, long duration) {
        mStartAnagle = startAngle;
        mSweepAngle = sweepAngle;
        setDuration(duration);
        setRepeatCount(Animation.INFINITE);
        setInterpolator(new LinearInterpolator());
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        if (!isComplete) {
            mSweepAngle = mSweepAngle + 6;
            if (mSweepAngle >= 360) {
                isComplete = true;
                mSweepAngle = 360;
            }
        } else {
            mStartAnagle = mStartAnagle + 6;
            mSweepAngle = mSweepAngle - 6;
            if (mStartAnagle >= 360)
                mStartAnagle = 0;
            if (mStartAnagle == 270 || mSweepAngle <= 0) {
                isComplete = false;
                mSweepAngle = 0;
            }
        }
        invalidate();
    }
}

解决方案

Maybe you should use Path:

Path path = new Path();
// Set the starting position of the path to (0,0).
path.moveTo(0, 0);
path.arcTo(...); //draw your arc here
path.circleTo(); //draw a small circle here at the end of arc

Also maybe you should calc the arc's end position and use as a center for small circle.

这篇关于在Android的弧形的边缘添加了一圈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆