Animation 向Android应用程序添加动画

Animation 向Android应用程序添加动画,animation,customization,Animation,Customization,我目前正在开发一个新的应用程序,我想为它添加定制的动画(不是说活动转换)。 为了让你明白我的意思,请看2:30-2:33的视频: 你看到胸部跳到屏幕上并以漂亮的动画顺利打开了吗? 我真的很想知道如何将它添加到Android应用程序中,它是帧动画吗? 我的意思是,我可以制作这个2D动画,我只想知道如何添加它(我使用的是Android Studio),而不会造成内存溢出 谢谢 请回答以下问题: 您可以看到胸部跳转到屏幕上,并以平滑的速度打开 美丽的动画?我真的很想知道如何将它添加到 Android

我目前正在开发一个新的应用程序,我想为它添加定制的动画(不是说活动转换)。 为了让你明白我的意思,请看2:30-2:33的视频:

你看到胸部跳到屏幕上并以漂亮的动画顺利打开了吗? 我真的很想知道如何将它添加到Android应用程序中,它是帧动画吗? 我的意思是,我可以制作这个2D动画,我只想知道如何添加它(我使用的是Android Studio),而不会造成内存溢出

谢谢

请回答以下问题:

您可以看到胸部跳转到屏幕上,并以平滑的速度打开 美丽的动画?我真的很想知道如何将它添加到 Android应用程序,是帧动画吗

我不认为这是一个帧动画。我想这是用OpenGL实现的。你可以找到官方教程

如果您想制作简单的2d动画,可以使用android提供的
AnimationDrawable
api。基本上,动画序列需要帧,然后可以使用以下代码创建动画:

// you would need an `ImageView` object as a placeholder for the animation
ImageView mMascotView = findViewById(...);

// prepare the animation object ..
AnimationDrawable mMascotAnimation = new AnimationDrawable();

final int frameTime = 250; // time in milliseconds

// adding the frames to the animation object. You can specify different
// times for each of these in milliseconds
mMascotAnimation.addFrame(getResources().getDrawable(R.drawable.frame1),frameTime);
mMascotAnimation.addFrame(getResources().getDrawable(R.drawable.frame2),frameTime);
mMascotAnimation.addFrame(getResources().getDrawable(R.drawable.frame3),frameTime);


// make it loop infinitely ..
mMascotAnimation.setOneShot(false);

// set the background of the `ImageView` as the `AnimationDrawable`object ..
mMascotView.setBackground(mMascotAnimation);

// start the animation ..
mMascotAnimation.start();
注意:您不应该在活动的
onCreate()
方法中调用
AnimationDrawable.start()
。视图还没有准备好。您应该在
onWindowFocusChanged()
方法上使用回调并在那里启动动画:

@Override
public void onWindowFocusChanged (boolean hasFocus)
{
      //Start animation here
      if(hasFocus) {
           mMascotAnimation.start();
      }
}

谢谢,非常详细