我试图更改转换侦听器中共享元素(ImageView(的可见性。但是这些更改只应用了一瞬间,然后返回到原始状态。
在这种情况下,我有一个照片查看器活动,它从共享元素转换动画开始,我想在动画结束后制作共享元素GONE
。然后添加一个照片视图片段。
window.getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
if (!isBackPressed) {
image.setVisibility(View.GONE);
addMediaFragment(uri);
}
}
@Override
public void onTransitionCancel(Transition transition) {
}
@Override
public void onTransitionPause(Transition transition) {
}
@Override
public void onTransitionResume(Transition transition) {
}
});
window.getSharedElementReturnTransition().addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
image.setVisibility(View.VISIBLE);
removeMediaFragment();
}
@Override
public void onTransitionEnd(Transition transition) {
}
@Override
public void onTransitionCancel(Transition transition) {
}
@Override
public void onTransitionPause(Transition transition) {
}
@Override
public void onTransitionResume(Transition transition) {
}
});
我建议您使用渐变动画并添加到过渡中
Fade moreScene = new Fade();
moreScene.addTarget(R.id.activity_new_layout_img);
moreScene.setDuration(300);
moreTransitionSet.addTransition(moreScene);