Android的计动画问题 [英] Android Gauge Animation Question

查看:499
本文介绍了Android的计动画问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我一直在努力做这几天​​,我没有得到的地方。所以,我有以下两个图像:

Okay so i've been trying to do this for a couple of days and i am getting no where. So i have the following two images:

第一个是RPM计

第二个图像是全白色的图形重新presenting转速计已满:

The Second image is a full white graphic representing rpm gauge being full:

我要做到以下几点:

  1. 询问用户的RPM输入,例如,如果他们进入1.2压力表将填补如下:

我有用户输入的工作,我需要与动画的帮助。以下是我曾尝试:

I have the user input working i need help with the animation. Here is what i have tried:

  1. 我使用PorterDuff尝试,但它也剪辑在后台计不仅白条
  2. 我已经试过分裂的形象到小位图,并将其存储到数组,这样我可以回忆的部分,但这是缓慢,经常死机
  3. 在我首先运用计到画布然后保存在画布上取得了一些进展:canvas.save();然后裁剪的白色图像,然后还原在画布上的路径。但是我不知道如何以循环方式从底部开始夹留下来了个180度可使到右下(CW)。这是最好的方法是什么?

我知道有可能这样做,我只是没有一个线索的更容易或更有效的方式。任何人只要有任何好的想法?

I know there is probably an easier or more efficient way of doing this i just don't have a clue. Anyone with any good ideas?

*注意:所有图像巴新

*Note all images are PNG's

在此先感谢!

推荐答案

正如你已经发现了,我会用夹子:

As you already found, i would use clip:

  • 在画背景图片
  • 设置剪贴
  • 在画的前景图像

我会用

Canvas.clipPath()

与路径看起来像扇形开始在圆心,像这样的:

with path looking like pie slice starting in the center of circle, like this:

要创建剪辑路径的使用是这样的:

To create clip path use something like:

public class PieView extends View {

    private int width = 200;
    private int angleStart = 135;
    private int sweep = 270;

    private Path p;

    private Paint paint = new Paint();

    public PieView(Context context, AttributeSet attrs) {
    super(context, attrs);
        p = new Path();
        //move into center of the circle
        p.setLastPoint(width/2, width/2);
        //add line from the center to arc at specified angle
        p.lineTo(width/2+(float)Math.cos(Math.toRadians(angleStart))*(width/2), 
                 width/2+(float)Math.sin(Math.toRadians(angleStart))*(width/2));
        //add arc from start angle with specified sweep
        p.addArc(new RectF(0, 0, width, width), angleStart, sweep);
        //from end of arc return to the center of circle
        p.lineTo(width/2, width/2);

        paint.setColor(Color.RED);
        paint.setStrokeWidth(1);
        paint.setStyle(Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawRect(0,0,width,width, paint);
        canvas.drawPath(p,paint);
    }
}

这篇关于Android的计动画问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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