Today I will talk about simple picture superimposed animation creation, frame animation

The frame animation created by the animation is the creation of the tween animation. An animation-list xml file is required to be used as the background of the IImageView control (note that it is the background background attribute). (Resources can leave mailboxes) similar to such an animation

First write an ImageView layout, set the basic properties and background properties as an xml file, this xml file includes the content of all pictures, and the display duration

    <ImageView
        android:id="@+id/iv_tun"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_name"
        android:background="@drawable/animition"
        />
下文问 xml 的文件,duration 为显示时长100ms
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/horse1" android:duration="100"></item>
<item android:drawable="@drawable/horse2" android:duration="150"></item>
<item android:drawable="@drawable/horse3" android:duration="100"></item>
<item android:drawable="@drawable/horse4" android:duration="150"></item>
<item android:drawable="@drawable/horse5" android:duration="100"></item>
<item android:drawable="@drawable/horse6" android:duration="150"></item>
<item android:drawable="@drawable/horse7" android:duration="100"></item>
<item android:drawable="@drawable/horse8" android:duration="150"></item>
</animation-list>
主文件(Activity)内容很简单:
<pre name="code" class="java">package com.wangban.yzbbanban.myapplicationanimation2;

import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ImageView ivRun= (ImageView) findViewById(R.id.iv_run);
        AnimationDrawable animationDrawable= (AnimationDrawable) ivRun.getBackground();
        animationDrawable.start();
    }
}
主方法(Activity)主要使用 AnimationDrawable这个类,而这个类是继承自DrawableContainer,DrawbaleContainer 继承Drawable的,getBackground()为 Drawable 的方法,所以调用此方法需要向下转型,那这个 AnimationDrawable 的作用是什么,android 中的注解是这样的:
 
 
An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.意思是:是一个一个可以用来创造一个画面到另一个画面的动作的对象,利用一些可以被作为 View 的背景的一些列图片作为对象。简单的就是,直接用一些可做动画的背景,直接创建动画。


Guess you like

Origin blog.csdn.net/u013377003/article/details/51408212