我正在创建一个计数器,它有一个可以输入和输出数字的动画。我在 xml 布局中有这个动画,通常每秒运行一次。正如您在下面的视频中看到的那样,我的动画做了一些额外的事情,它不能正常工作。
我的动画xml代码是:
<?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>
我的“计时器”代码读取系统时间并启动动画并更改数字是:
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);
}
}
关于我可以更改什么以正确查看动画的任何想法?我认为时间很好,最终动画的持续时间为 700 毫秒,并且每 1000 毫秒启动一次。