I'm creating a counter that have an animation that takes the number in and out. I have this animation in an xml layout, and normally is runned once per second. My animations do things extrange as you can see in the following video, it doesn't ork properly.
My xml code for the animation is:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="350"/>
<scale
android:fromXScale="2.0"
android:toXScale="1.0"
android:fromYScale="2.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="350"/>
</set>
And my code for the "chronometer" that reads the time of the system and start the animation and change the number is:
void onTime() { //this function is executed more than 1 time per second...
long y=System.currentTimeMillis()-start; //start is initialized on the onCreate
if (isBetween(Integer.parseInt(Long.toString(y)), 1000, 1070)) {
time.setText("3");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
} if (isBetween(Integer.parseInt(Long.toString(y)), 2000, 2070)) {
time.setText("2");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 3000, 3070)) {
time.setText("1");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 4000, 4070)) {
time.setText("GOOO!");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
count.setVisibility(View.VISIBLE);
cuenta = 0;
count.setText("0");
}else if (isBetween(Integer.parseInt(Long.toString(y)), 5000, 5070)) {
time.setText("1");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 6000, 6070)) {
time.setText("2");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 7000, 7070)) {
time.setText("3");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 8000, 8070)) {
time.setText("4");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 9000, 9070)) {
time.setText("5");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
}else if (isBetween(Integer.parseInt(Long.toString(y)), 10000, 10070)) {
time.setText("Time!");
time.setAnimation(anim);
System.out.println(Integer.parseInt(Long.toString(y)));
//count.setVisibility(View.INVISIBLE);
int finalcount = cuenta;
System.out.println(finalcount);
}
}
Any ideas about what can I change to see the animation correctly? I think that the times are well, at final, the animations have a duration of 700ms, and are started every 1000ms.