问题描述
- android 中的动画无效果
-
image = (ImageView) findViewById(R.id.main_img);
start = (Button) findViewById(R.id.main_start);
cancel = (Button) findViewById(R.id.main_cancel);final TranslateAnimation animation = new TranslateAnimation(0, -150,0, -150); animation.setDuration(2000);//设置动画持续时间 animation.setRepeatCount(2);//设置重复次数 animation.setRepeatMode(Animation.REVERSE);//设置反方向执行 image.setAnimation(animation); animation.start(); start.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { animation.start(); } }); cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
/** 结束动画 */
animation.cancel();
}
});程序运行的时候有动画效果,当点击start按钮的时候,image没有移动动画,谁知道为什么吗?
解决方案
image.setAnimation(animation);这句放到点击代码中
解决方案二:
我之前开发的时候遇到过这个问题,原因是动画是需要异步加载的,当activity完成的时候,动画还没准备好,你可以实现一个OnTouchListener的接口,把这个动画开启的方法放进去
解决方案三:
已解决,改调用startanimation
解决方案四:
startanimation 放在了哪里啊 我也是安卓刚入门 求教啊
解决方案五:
还有这句话是什么意思呢 startanimation
时间: 2024-08-01 09:41:28