Android---Frame动画示例
Frame动画:
1、找到一组图片c01.jpg,c02.jpg,c03.jpg,c04.jpg,c05.jpg,copy到res/drawable目录下;
2、在res/drawable目录下新建XML文件:frame_anim.xml
[html]
<?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/c01" android:duration="500"/>
<item android:drawable="@drawable/c02" android:duration="500"/>
<item android:drawable="@drawable/c03" android:duration="500"/>
<item android:drawable="@drawable/c04" android:duration="500"/>
<item android:drawable="@drawable/c05" android:duration="500"/>
</animation-list>
<?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/c01" android:duration="500"/>
<item android:drawable="@drawable/c02" android:duration="500"/>
<item android:drawable="@drawable/c03" android:duration="500"/>
<item android:drawable="@drawable/c04" android:duration="500"/>
<item android:drawable="@drawable/c05" android:duration="500"/>
</animation-list>3、在res/layout目录下新建XML文件:frame_anim_layout.xml
[html]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="@+id/imgFrame"
android:background="@drawable/frame_anim"></ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="开始"
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"></Button>
<Button
android:text="结束"
android:id="@+id/btnEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"></Button>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:id="@+id/imgFrame"
android:background="@drawable/frame_anim"></ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="开始"
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"></Button>
<Button
android:text="结束"
android:id="@+id/btnEnd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"></Button>
</LinearLayout>
</LinearLayout>4、Activity文件中的代码:
[java]
package com.bison;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class AnimationDemoActivity extends Activity implements OnClickListener {
// 开始按钮
private Button btnStart;
// 结束按钮
private Button btnEnd;
private ImageView imgFrame;
// 声明Frame动画对象
private AnimationDrawable frameAnim;
/** 初始化 */
public void init() {
btnStart = (Button) findViewById(R.id.btnStart);
btnEnd = (Button) findViewById(R.id.btnEnd);
btnStart.setOnClickListener(this);
btnEnd.setOnClickListener(this);
imgFrame = (ImageView) findViewById(R.id.imgFrame);
// 将ImageView的backgroud声明给Frame动画对象
frameAnim = (AnimationDrawable) imgFrame.getBackground();
}
&
补充:移动开发 , Android ,