小编bek*_*bek的帖子

在Android时钟中移动分钟

我正在尝试编写一个简单的概念证明应用程序,允许用户旋转时钟的分针.我很难为OnTouchEvent提供正确的逻辑.

到目前为止,我有以下代码:

    public boolean onTouchEvent(MotionEvent e) {

       float x = e.getX();
       float y = e.getY();

    switch (e.getAction()) {
    case MotionEvent.ACTION_MOVE:
        //find an approximate angle between them.

        float dx = x-cx;
        float dy = y-cy;
        double a=Math.atan2(dy,dx);

        this.degree = Math.toDegrees(a);
        this.invalidate();
    }
    return true;
    }


protected void onDraw(Canvas canvas) {
    super .onDraw(canvas);

    boolean changed = mChanged;
    if (changed) {
        mChanged = false;
    }

    int availableWidth = getRight() - getLeft();
    int availableHeight = getBottom() - getTop();

    int x = availableWidth / 2; …
Run Code Online (Sandbox Code Playgroud)

java math android

6
推荐指数
1
解决办法
2547
查看次数

标签 统计

android ×1

java ×1

math ×1