Hi all,
I have written an application where I have a speedometer with a needle vertically set at 90 degree and I am trying to rotate the needle around its center with the speed that changes for every one second(I am displaying the speed in a text view that changes randomly from 0 to 120)
I am getting the speed from a remote service and displaying in a textview.
so as the speed changes the speedometer needle gauge should change accordingly around its center. I mean If speed is 30 the needle should be at 30 and so on in speedometer.
My code is not working exactly, How to get around this problem?
Help is always appreciated,Thanks.
Here is my code:
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");
}
}
}