Android 使用 ObjectAnimation 的工作室动画
Android Studio Animation Using ObjectAnimation
我一直在尝试为按钮制作动画,但 none 的动画在它上面起作用。单击某些内容后,我不会尝试为某些内容设置动画。我想在调用此函数时为其设置动画。有人知道为什么我的按钮拒绝动画吗?
private void eliminate() {
for (int i = 0; i == 0; i++) {
int randomJ = getRandomNumberInRange(0, 2);
int randomI = getRandomNumberInRange(0, 2);
if (!buttons[randomI][randomJ].getText().toString().equals("")) {
buttons[randomI][randomJ].setText("");
objectAnimator = ObjectAnimator.ofFloat(buttons[randomI][randomJ], "rotation", 180);
objectAnimator2 = ObjectAnimator.ofFloat(buttons[randomI][randomJ], "alpha", 1);
objectAnimator.setDuration(5000);
} else {
i -= 1;
}
}
}
您似乎没有在动画中添加 .start() 方法。
下面是我制作的一个简单示例,其布局具有一个 TextView 元素,其 id "textview":
TextView animateTextView = (TextView) findViewById(R.id.textview);
ObjectAnimator textViewAnimator = ObjectAnimator.ofFloat(animateTextView, "translationY",0f,500f);
textViewAnimator.setDuration(2000);
textViewAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
textViewAnimator.start();
我一直在尝试为按钮制作动画,但 none 的动画在它上面起作用。单击某些内容后,我不会尝试为某些内容设置动画。我想在调用此函数时为其设置动画。有人知道为什么我的按钮拒绝动画吗?
private void eliminate() {
for (int i = 0; i == 0; i++) {
int randomJ = getRandomNumberInRange(0, 2);
int randomI = getRandomNumberInRange(0, 2);
if (!buttons[randomI][randomJ].getText().toString().equals("")) {
buttons[randomI][randomJ].setText("");
objectAnimator = ObjectAnimator.ofFloat(buttons[randomI][randomJ], "rotation", 180);
objectAnimator2 = ObjectAnimator.ofFloat(buttons[randomI][randomJ], "alpha", 1);
objectAnimator.setDuration(5000);
} else {
i -= 1;
}
}
}
您似乎没有在动画中添加 .start() 方法。 下面是我制作的一个简单示例,其布局具有一个 TextView 元素,其 id "textview":
TextView animateTextView = (TextView) findViewById(R.id.textview);
ObjectAnimator textViewAnimator = ObjectAnimator.ofFloat(animateTextView, "translationY",0f,500f);
textViewAnimator.setDuration(2000);
textViewAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
textViewAnimator.start();