关于动画的代码(启动和取消,只是一个简单的演示)适用于Android API 10,但是当我在API19上运行它时,它不起作用,我不知道为什么? 谁知道为什么,你能指导我吗?
public class Animation_Act extends AppCompatActivity implements View.OnClickListener {
private Button mIdBtnStartAnimation;
private Button mIdBtnStopAnimation;
private ImageView mIdIvFlag;
Animation translateAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_cancel);
mIdBtnStartAnimation = (Button) findViewById(R.id.id_btn_startAnimation);
mIdBtnStopAnimation = (Button) findViewById(R.id.id_btn_stopAnimation);
mIdIvFlag = (ImageView) findViewById(R.id.id_iv_flag);
mIdBtnStartAnimation.setOnClickListener(this);
mIdBtnStopAnimation.setOnClickListener(this);
translateAnimation = new TranslateAnimation(0, 200, 0, 200);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.id_btn_startAnimation:
translateAnimation.setDuration(3000);
mIdIvFlag.setAnimation(translateAnimation);
translateAnimation.startNow();
break;
case R.id.id_btn_stopAnimation:
translateAnimation.cancel();
break;
default:
break;
}
}
}