您的位置:首页 > 其它

帧动画低版本模拟器不运行的问题,完美解决

2016-03-10 17:37 381 查看
在Activity中调用Aniamtion:
1.
image.setBackgroundResource(R.anim.butterfly);

2.
image2.setBackgroundResource(R.anim.leftbutterfly);

3.
AnimationDrawable animation = (AnimationDrawable) image.getBackground();

4.
animation.start();

5.
AnimationDrawable animation2 = (AnimationDrawable) image2.getBackground();

6.
animation2.start();
这里获取到了animation,要开始动画只需animation.start();即可。但问题是,我的2.3机子不能播放。因为不能在Activity的onCreate()方法里调用该方法,此时AnimationDrawable类尚未完全与window接触,可以安排一个TouchEvent触发启动animation,如果希望一开始就播放动画,就要加入一个onWindowFocusChanged()方法来启动,
1.
public

void
onWindowFocusChanged(
boolean

hasFocus) {

2.
// TODO Auto-generated method stub

3.
super
.onWindowFocusChanged(hasFocus);

4.
animation.start();

5.
}



@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 初始化起点坐标
startX = (int) event.getRawX();
startY = (int) event.getRawY();
anim.start();
break;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: