Android的,我怎么能旋转的箭头(图)围绕一个固定点? [英] Android, How can I rotate an arrow (image) around a fixed point?

查看:333
本文介绍了Android的,我怎么能旋转的箭头(图)围绕一个固定点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要旋转从0到180度的箭头图像(如在一米的针头。)一个点的箭头是固定在中间,并在箭头的屏幕和头部应该移动的底部。箭头的长度是固定(这是图像)。另外我有两个按钮,我想箭头向左转时,按钮左边是感动和右转时,触摸右边的按钮。

I have an arrow image that I want to rotate from 0 to 180 degree (like the needle in a meter.) One point of the arrow is fixed in middle and at bottom of the screen and head of arrow should move. Length of arrow is fix (it is image). Also I have two buttons and I want arrow to turn left when button left is touched and turn right when right button is touched.

这是这一进程的逻辑?

What is the logic of this process?

推荐答案

这其实是,如果你使用的是帆布做你的绘图pretty的简单(因为你应该在你的案件)。

This is actually pretty simple if you are using a canvas to do your drawing(as you should in your case).

既然你知道的坐标为点周围的图像应该旋转,你可以做到这一点是这样的:

Given that you know the coordinates for the point around which the image should rotate, you can do it like this:

private void doDraw(Canvas canvas) {
canvas.save();
float px = ...;
float py = ...;
canvas.rotate(degrees, px, py);
arrow.draw(canvas);
canvas.restore();
}

度将是您递增当用户点击L或R按钮/递减一个整数值。 canvas.rotate取剩下的工作!

degrees will be a integer value that you increment/decrement when the user clicks the L or R buttons. canvas.rotate takes care of the rest!

这篇关于Android的,我怎么能旋转的箭头(图)围绕一个固定点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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