When starting an activity:
ActivityCompat.startActivity(Intent(this@BeforeActivity,BeforeTwoActivity::class.java), ActivityOptionsCompat.makeCustomAnimation(this@BeforeActivity, android.R.anim.fade_in, android.R.anim.fade_out).toBundle())
####When finish ing:
ActivityCompat.finishAfterTransition(this)
However, after this method is called, it will be found that there is no soft use and no exit animation. After debugging, it is found that:
public boolean startExitBackTransition(final Activity activity) { if (mEnteringNames == null || mCalledExitCoordinator != null) { return false; } else { ... } }
The mEnteringNames is always null, and the variable is related to the shared element:
/** * The shared elements that the calling Activity has said that they transferred to this * Activity. * The shared element calling the Activity indicates that it has been transferred to this Activity (please don't mind this machine flip, gather and look) */ private ArrayList<String> mEnteringNames;
Because shared elements are involved between the two pages, which are not used here, if you want to have an appearance animation, you should call overridePendingTransition() to display it (please let us know if there is a better method, thank you very much)
Second
ActivityOptionsCompat makeScaleUpAnimation(View source,int startX, int startY, int startWidth, int startHeight)
A small area displayed by this effect is enlarged to the full screen display, and the effect is as follows:
The first parameter of this method is the target view (that is, the view to be enlarged), the second and third parameters are the starting coordinates, and the fourth and fifth parameters are the width and height at the beginning of the transition effect. Use the following:
When starting an activity:
val options = ActivityOptionsCompat.makeScaleUpAnimation(view,view.width/2,view.height/2, 0, 0) ActivityCompat.startActivity(this@AfterActivity,Intent(this@AfterActivity,AfterTwoActivity::class.java),options.toBundle())
When finish ing (there is no fallback effect, no solution has been found for the time being, please let us know if there is a better method, thank you very much):
ActivityCompat.finishAfterTransition(this)
Second
ActivityOptionsCompat makeScaleUpAnimation(View source,int startX, int startY, int startWidth, int startHeight)
A small area displayed by this effect is enlarged to the full screen display, and the effect is as follows:
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-6luxfl2r-1630921054771)( https://user-gold-cdn.xitu.io/2017/12/20/160731d9b09e58a6?imageslim )]
The first parameter of this method is the target view (that is, the view to be enlarged), the second and third parameters are the starting coordinates, and the fourth and fifth parameters are the width and height at the beginning of the transition effect. Use the following:
When starting an activity:
val options = ActivityOptionsCompat.makeScaleUpAnimation(view,view.width/2,view.height/2, 0, 0) ActivityCompat.startActivity(this@AfterActivity,Intent(this@AfterActivity,AfterTwoActivity::class.java),options.toBundle())
When finish ing (there is no fallback effect, no solution has been found for the time being, please let us know if there is a better method, thank you very much):
ActivityCompat.finishAfterTransition(this)
Third
ActivityOptionsCompat makeThumbnailScaleUpAnimation(View source,Bitmap thumbnail, int startX, int startY)
This effect shows the animation of Bitmpat stretching a piece. The effect is as follows:
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-wdl3yfog-1630921054773)( https://user-gold-cdn.xitu.io/2017/12/20/160731d9a6c83fce?imageslim )]
The first parameter of this method is the target view (that is, the view to be enlarged), the second parameter is the picture to be enlarged, and the fourth and fifth parameters are the starting coordinates, which are used as follows:
When starting an activity:
var bitmap = BitmapFactory.decodeResource(resources,effect.uri) val options = ActivityOptionsCompat.makeThumbnailScaleUpAnimation(view, bitmap, view.width/2, view.height/2) ActivityCompat.startActivity(this@AfterActivity,Intent(this@AfterActivity,AfterTwoActivity::class.java),options.toBundle())
When finish ing (there is no fallback effect, no solution has been found for the time being, please let us know if there is a better method, thank you very much):
ActivityCompat.finishAfterTransition(this)
Fourth
ActivityOptionsCompat makeClipRevealAnimation(View source,int startX, int startY, int width, int height)
This effect shows a circular gradient from one point to the full screen, and the effect is as follows:
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-yup8oqtk-1630921054774)( https://user-gold-cdn.xitu.io/2017/12/20/160731d9a2ba5e9d?imageslim )]
The first parameter of this method is the target view (that is, the view to be enlarged), the second and third parameters are the starting coordinates, and the fourth and fifth parameters are the width and height at the beginning of the transition effect. Use the following:
When starting an activity:
val options = ActivityOptionsCompat.makeClipRevealAnimation(view,view.width/2, view.height/2,0, 0) ActivityCompat.startActivity(this@AfterActivity,Intent(this@AfterActivity,AfterTwoActivity::class.java),options.toBundle())
When finish ing (there is no fallback effect, no solution has been found for the time being, please let us know if there is a better method, thank you very much):
ActivityCompat.finishAfterTransition(this)
Fifth
####ActivityOptions CompatmakeSceneTransitionAnimation(Activity activity,Pair<View, String>... sharedElements)
The various effects of this display are as follows:
[external chain picture transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-tcmtoibj-1630921054776)( https://user-gold-cdn.xitu.io/2017/12/20/160731d9a078d5a9?imageslim )]
The first parameter of this method is the target view (that is, the view to be enlarged), and the second parameter is required for shared elements (the effect here is not involved). Use the following:
When starting an activity:
startActivity(Intent(this@AfterActivity, AfterTwoActivity::class.java), ActivityOptionsCompat.makeSceneTransitionAnimation(this@AfterActivity).toBundle())
Then set the effect on the page after jump (aftertwoactivity here):
tivity::class.java),
ActivityOptionsCompat.makeSceneTransitionAnimation(this@AfterActivity).toBundle())
#### Then set the effect on the page after jump (aftertwoactivity here):