How can I add an animation to the activity finish()

后端 未结 8 1798
清酒与你
清酒与你 2020-11-27 13:37

I\'m using overridePendingTransition for when my activity is created and that works fine I can see the fade in works great, but when I try and animate the finish on the acti

相关标签:
8条回答
  • 2020-11-27 14:08

    I would suggest to use isFinishing() method to configure the animations at onPause instead of calling finish()

    @Override
    protected void onPause() {
        super.onPause();
        if (isFinishing()){
            overridePendingTransition(R.anim.activity_slide_in, R.anim.activity_slide_out);
        }
    
    }
    
    0 讨论(0)
  • 2020-11-27 14:16

    I fixed this issue using this kind of approach:

    to open with animation:

     Intent newUser = new Intent(getBaseContext(), NewUserActivity.class);
        startActivity(newUser);
        overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
    

    To close with animation:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        onBackPressed();
        return super.onOptionsItemSelected(item);
    }
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.slide_out_right,R.anim.slide_in_right);
    }
    
    0 讨论(0)
  • 2020-11-27 14:19

    Use startActivityForResult to start your child activity and in onActivityResult() of your parent activity:

        @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==REQUEST_YOUR_ACTIVITY) {
            overridePendingTransition(R.anim.parent_appearing_anim, R.anim.child_dissmissing_anim);
        }
        super.onActivityResult(requestCode, resultCode, arg2);
    }
    
    0 讨论(0)
  • 2020-11-27 14:26

    This question has already answered but the most efficient way to put an animation while exiting from an activity is by overriding the "finish()" method of the related activity:

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.hold, R.anim.slide_out_bottom);
    }
    
    0 讨论(0)
  • 2020-11-27 14:29
    finish();
    overridePendingTransition(0, 0);
    
    0 讨论(0)
  • 2020-11-27 14:29

    Following on the answer by @schwiz, here is an animation override for the built-in Dialog theme, where I have defined local slide_up and slide_down animations. My activity specifies the theme MyDialog in order to have these transitions in and out.

    <style name="Animation.MyDialog" parent="android:Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/slide_up</item>
        <item name="android:windowExitAnimation">@anim/slide_down</item>
    </style>
    
    <style name="Theme.MyDialog" parent="android:Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/Animation.MyDialog</item>
    </style>
    

    0 讨论(0)
提交回复
热议问题