ANDROID - 逐帧动画

标签 android animation

我是安卓初学者。我需要在应用程序中实现逐帧动画,但我不知道它是如何完成的,请给我完整的逐帧动画示例。

最佳答案

您好,您可以通过此步骤来完成此操作。

Step 1 : Insert images in drawable folder which need for framing.

Step 2 : Create an xml for configure for FrameByFrame animation and place it into res/drawable folder. Here there are two images are use for animation is f1 and f2. android:duration defines time in milisecond for change frame.

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
   <item
       android:drawable="@drawable/f1"
       android:duration="50"/>
   <item
       android:drawable="@drawable/f2"
       android:duration="50"/>
</animation-list>

Step 3 : Create main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >

   <ImageView
       android:id="@+id/imageView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />
</RelativeLayout>

Step 4 : Finally execute in MainActivity.java

public class MainActivity extends Activity {
ImageView iv;

@Override
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       // Imageview in which images load one by one like Frame By Frame
       iv = (ImageView) findViewById(R.id.imageView1);
       //Bind xml which is configure animation.
       AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(
            R.drawable.sam);
       iv.setBackgroundDrawable(ad);
       //Start animation
       ad.start();
       //For stop animation you can use ad.stop();
   }
}

关于ANDROID - 逐帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965690/

相关文章:

android - 重复的 id,标签为空,带有 androidx.navigation.fragment.NavHostFragment 的另一个 fragment

android - BLE Android写入特征数据

animation - 我怎样才能最好地在 Unity3d 中为 2D Sprite 设置动画?

c# - 控制模板中的 Storyboard 访问属性

android - 使用脚手架在 Material Design 3 中显示 Snackbar

android - 无论如何,Android和IOS都可以在后台发送短信吗?

java - 如果用户通过单击同一按钮返回 Activity ,请保持 RecyclerView 适配器复选框处于选中状态[Kotlin]

c# - 如何仅使用 C# 代码(在 WPF 窗口内)在图像对象上创建旋转动画

没有jquery的Javascript动画

python - 在 python/matplotlib 中动画补丁对象