Frame animation, playing animation is like flash, playing frame by frame, that is to say, the image is the continuous playing of some pictures with similar actions, and the effect achieved is like the effect of video playing.
How to achieve the effect of frame animation: create a file under the drawable file, take the animation list as the root element, then create item sub elements under the root element, and finally add attributes to the sub elements. I will post my code below:
1. Layout file code
(1) . layout file code
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.Tween_Animation.Alpha_MainActivity" >
<Button
android:id="@+id/button_scale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_stringScaleAnimation" />
<LinearLayout
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageview_scale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
(2) xml code under. Drawable file
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/one"
android:duration="500"/>
<item
android:drawable="@drawable/one"
android:duration="500"/>
<item
android:drawable="@drawable/one"
android:duration="500"/>
</animation-list>
2. activity code
package com.example.Frame_Animation;
import com.example.androidanimation.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity implements OnClickListener{
private Button button = null;
private ImageView imageview = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button_scale);
imageview = (ImageView) findViewById(R.id.imageview_scale);
button.setOnClickListener(this);
}
public void onClick(View v) {
//Load the created xml file
imageview.setImageResource(R.drawable.list);
}
}