问题描述
我正在两次活动之间使用Shared Element Transitions
.过渡效果很好,但是我想知道共享元素过渡的结束时间,以便我可以展示其他内容.
I am working with Shared Element Transitions
between activities. The transition is working fine but I want to know when the shared element transition ends so that I can show other things.
我尝试在要转换的活动中的SharedElementCallback
中使用onSharedElementEnd
,但是在转换开始之前会被调用.
I tried using onSharedElementEnd
in SharedElementCallback
in the activity I am transition to but that gets called before the transition starts.
我可以听另一个回调吗?
is there another callback i can listen for?
推荐答案
您是否尝试将动画侦听器绑定到onMapSharedElements
内部的共享元素视图? ViewCompat.animate(view)
将为您提供新的或缓存的ViewPropertyAnimator(Compat)
,然后绑定动画侦听器应该很简单.不过,我还没有尝试过.
Did you try to bind animation listener to the shared element view inside onMapSharedElements
? ViewCompat.animate(view)
will give you either a new or cached ViewPropertyAnimator(Compat)
and then binding the animation listener should be trivial. I haven't tried it, though.
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
super.onMapSharedElements(names, sharedElements);
View keySharedElementView = sharedElements.get("keySharedElement");
if(keySharedElementView != null){
ViewCompat.animate(keySharedElementView).setListener(new ViewPropertyAnimatorListenerAdapter(){
@Override
public void onAnimationEnd(View view) {
super.onAnimationEnd(view);
}
});
}
}
});
如何在共享元素过渡中添加Transition.Listener
?
What about adding Transition.Listener
to the shared element transition?
Transition sharedElementEnterTransition = getWindow().getSharedElementEnterTransition();
sharedElementEnterTransition.addListener(new TransitionListenerAdapter() {
@Override
public void onTransitionEnd(android.support.transition.Transition transition) {
super.onTransitionEnd(transition);
}
});
这篇关于如何知道共享元素转换何时结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!