我正在尝试使用很棒的库 AndroidViewAnimations .
我有两个动画,一个在您按下按钮时播放,一个在 Activity 开始时播放。
当您按下按钮时,动画表现正常,但在 onCreate 方法中执行的动画表现异常。
public class TestActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
//This happens when you start the activity
YoYo.with(Techniques.Tada).duration(1000).playOn(findViewById(R.id.hello_world));
}
//This happens when you click the button
public void animate(View view) {
YoYo.with(Techniques.Tada).duration(1000).playOn(findViewById(R.id.hello_world));
}
在 onCreate 方法中执行的动画似乎是从左上角开始的,而当您按下按钮时执行的动画是从中心开始的。后者是正确的行为。
onCreate:动画从左上角开始。 - 不正确
按钮:动画从中心开始。 - 正确
任何人都知道什么可能导致奇怪的行为?
最佳答案
我通过实现 onWindowFocusChanged 方法解决了这个问题:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
YoYo.with(Techniques.Tada).duration(1000).playOn(findViewById(R.id.hello_world));
}
}
关于AndroidViewAnimations 在 onCreate 中无法正确设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27826516/