简体   繁体   English

如何在活动的活动按下时覆盖共享元素的平滑过渡?

[英]How to override shared element smooth transition in activity's on back pressed?

I have started a details activity from a list activity and a couple of shared elements have been animated using ActivityCompat.startActivity() and obviously when the onBackPressed() of the activity is called the smooth transition is reversed. 我已经从列表活动中开始了一个Details活动,并且使用ActivityCompat.startActivity()对两个共享元素进行了动画处理,显然,当该ActivityCompat.startActivity()onBackPressed()称为平滑过渡时,就可以反转了。

But here in my case it creates a problem; 但是在我看来,这会带来问题。 the details activity utilizes swiping gestures to browse trough the listItems one by one; details活动利用滑动手势来逐一浏览listItem。 and when user is about to return, the smooth transition animates the wrong image and title and in the end the actual image and title of that row is replaced which doesn't creates a smooth transition at all. 当用户要返回时,平滑过渡会为错误的图像和标题添加动画效果,最后替换该行的实际图像和标题,这根本不会创建平滑过渡。

I'm trying to use a replacement fadeIn\\fadeOut animation for activities when the onBackPressed() is called if the position differs the original clicked position, but calling super.onBackPressed() doesn't do the magic. 我试图用更换淡入\\淡出动画活动时onBackPressed()如果位置不同,原来的点击位置,但在调用super.onBackPressed()不会做的魔力。

here's the method: 方法如下:

   @Override
public void onBackPressed() {
    if (originalPosition != positionInParentList) {
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        return;
    }
    super.onBackPressed();
}

Replace the order of statements, Bring the super.onBackPressed(); 替换语句的顺序,带super.onBackPressed(); above the if statement. 在if语句上方。

Try this: 尝试这个:

@Override
public void onBackPressed() {
    super.onBackPressed();
    if (originalPositionInParentList == positionInParentList) {
        return;
    }
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM