【发布时间】:2012-08-01 06:31:07
【问题描述】:
大家好,
我编写了一个应用程序,其中我有一个速度计,其指针垂直设置为 90 度,我试图以每秒变化的速度围绕其中心旋转指针(我在文本中显示速度从 0 到 120 随机变化的视图)
我正在从远程服务获取速度并在文本视图中显示。
因此,随着速度的变化,速度表针规应围绕其中心相应变化。我的意思是,如果速度为 30,则速度表中的指针应为 30,依此类推。
我的代码不能正常工作,如何解决这个问题?
我们非常感谢您的帮助,谢谢。
这是我的代码:
pointer1 = (ImageView) findViewById(R.id.pointer1);
double degrees= speed;
double angle = degrees * 2 * Math.PI / 360.0;
for( speed=0;speed<120;speed++){
RotateAnimation rAnimAntiClockWise = new RotateAnimation(180-0.0f, 180-speed,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rAnimAntiClockWise.setInterpolator(new LinearInterpolator());
rAnimAntiClockWise.setDuration(100);
rAnimAntiClockWise.setFillAfter(true);
rAnimAntiClockWise.setDuration(10000);
rAnimAntiClockWise.setRepeatCount(-1);
rAnimAntiClockWise.setRepeatMode(2);
pointer1.startAnimation(rAnimAntiClockWise);
}
private void invokeService() {
if (conn == null) {
} else {
try {
System.out.println(remoteService);
int speed = remoteService.getSpeed();
System.out.println("myspeed" + speed);
TextView r = (TextView) findViewById(R.id.text2);
r.setText("" + Integer.toString(speed));
Log.d(getClass().getSimpleName(), "invokeService()");
} catch (RemoteException re) {
Log.e(getClass().getSimpleName(), "RemoteException");
}
}
}
【问题讨论】:
-
我的代码不能正常工作 > 它在做什么?你的错误是什么?
-
@Anders Metnik,没有错误,但它以逆时针方式无限旋转 90 到 45 度
-
是的,这是有道理的,这似乎也是您在代码中要求它执行的操作?
-
hmmm,但是如果spped是120那么它应该根据速度变化然后针应该在120,我必须根据速度设置针规的角度。因为我是新人到android我做不到。我尝试了很多但没有结果
-
Hii Raghav 你检查过这个例子吗atstechlab.wordpress.com/2010/07/30/…
标签: android center angle image-rotation