Make new activity appear behind old one during transition

前端 未结 3 1143
有刺的猬
有刺的猬 2020-11-29 20:23

What I\'m trying to achieve is to override the start activity animation.

The animation should give the impression that the old activity is on top of the new activity

相关标签:
3条回答
  • 2020-11-29 20:54

    Actually, I've found a property called android:zAdjustment in the animation files.

    If I put android:zAdjustment="bottom" in hold.xml (screen 2) and android:zAdjustment="top" in push_down_out.xml (screen 1) then I can get the desired effect.

    This gets around the z order issue (I assumed it was an issue with animation timings so I was barking up the wrong tree).

    John

    0 讨论(0)
  • 2020-11-29 21:01

    The solution that works for me:

    R.anim.exit_slide_down

    <set xmlns:android="http://schemas.android.com/apk/res/android" 
         android:zAdjustment="top">  
    
        <translate android:fromYDelta="0" 
                   android:toYDelta="100%p" 
                   android:duration="600" />
    </set>
    

    ...and then

    Intent intent = new Intent(activity, SecondActivity.class);
    startActivity(intent);
    activity.overridePendingTransition(0, R.anim.exit_slide_down);
    
    0 讨论(0)
  • 2020-11-29 21:02

    I've been trying to solve your solution in a sample project and I got it working with this code:

    Call the animation with:

    startActivity(new Intent(this, Activity2.class));
    overridePendingTransition(R.anim.push_down_in,R.anim.push_down_out);
    

    R.anim.push_down_in:

    <?xml version="1.0" encoding="utf-8"?>  
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
      <translate android:fromYDelta="-100%p" android:toYDelta="0" android:duration="300"/>
    </set>  
    

    R.anim.push_down_out:

    <?xml version="1.0" encoding="utf-8"?>  
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
      <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="300"/>
    </set>  
    
    0 讨论(0)
提交回复
热议问题