Animation.startNow无法在高API级别上运行

时间:2016-04-15 08:36:30

标签: java android android-animation

关于动画的代码(启动和取消,只是一个简单的演示)适用于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;
        }
    }
}

0 个答案:

没有答案