android activity 切换动画

如何添加Activity的进出场动画

必须在 StartActivity() 或 finish() 之后立即调用overridePendingTransition方法

public static void actionStart(Activity activity, int id, int category) {
    Intent intent = new Intent(activity, QLibraryDetialActivity.class);
    intent.putExtra("id", id);
    intent.putExtra("category", category);
    activity.startActivity(intent);
    // 设置切换动画,从右边进入,左边退出; 
    // 两个activity切换,第一个activity从0位左移退出,第二个activity从100%位左移进入(下面参数1是第二个activity的动画)
    activity.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}

动画xml slide_in_right:



    
    

动画xml slide_out_left:



    
    

用在finish()后:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode){
        case KeyEvent.KEYCODE_BACK:
            myFinish();
            break;
    }
    return super.onKeyDown(keyCode, event);
}

private void myFinish() {
    finish();
    overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
}

动画slide_in_left:



    
    

动画slide_out_right:



    
    

你可能感兴趣的:(android activity 切换动画)