2020-03-08|1072阅|作者:子清|举报 摘要:[android]代码库
view source
print?
package com.example.ch08_5_frameanimation;
[android]代码库
package com.example.ch08_5_frameanimation;
|
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 FrameActivity extends Activity {
|
public void onCreate(Bundle savedInstanceState) { //重写onCreate方法
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.main);
|
Button btn = (Button)findViewById(R.id.btn);
|
btn.setOnClickListener(new OnClickListener() { //为按钮设置监听器
|
public void onClick(View v) { //重写onClick方法
|
ImageView iv = (ImageView)findViewById(R.id.iv);
|
iv.setBackgroundResource(R.anim.hero_left);
|
AnimationDrawable ad = (AnimationDrawable)iv.getBackground();
|
ad.start(); //启动AnimationDrawable
|
Button btn1 = (Button)findViewById(R.id.btn1);
|
btn1.setOnClickListener(new OnClickListener() { //为按钮设置监听器
|
public void onClick(View v) { //重写onClick方法
|
ImageView iv = (ImageView)findViewById(R.id.iv);
|
iv.setBackgroundResource(R.anim.hero_right);
|
AnimationDrawable ad = (AnimationDrawable)iv.getBackground();
|
ad.start(); //启动AnimationDrawable
|