Android:加速活动之间的共享元素转换
Android: speeding up shared element transition between activities
我有两个活动之间的共享元素转换,其工作方式如下:
Intent someintent = new Intent(this, someclass.class);
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this
, new Pair<>(viewClicked.findViewById(R.id.someimage), "someimage")
, new Pair<>(viewClicked.findViewById(R.id.someicon), "someicon")
);
startActivity(someintent, options.toBundle());
}
else {
startActivity(someintent);
}
这工作正常,但转换速度慢得令人痛苦。当第一次点击图像时,它似乎会在转换发生之前停顿一两秒钟。这是由于正在加载 activity 的 "weight" 还是延迟可配置?
您是否尝试更改 enterTransition
和 returntransition
的持续时间:
private Transition enterTransition() {
ChangeBounds bounds = new ChangeBounds();
bounds.setDuration(2000);
return bounds;
}
private Transition returnTransition() {
ChangeBounds bounds = new ChangeBounds();
bounds.setInterpolator(new DecelerateInterpolator());
bounds.setDuration(2000);
return bounds;
}
在onCreate
中:
getWindow().setSharedElementEnterTransition(enterTransition());
getWindow().setSharedElementReturnTransition(returnTransition());
另一种可能对某些已经在其样式中设置了转场效果的人有帮助的方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getSharedElementEnterTransition().setDuration(2000);
getWindow().getSharedElementReturnTransition().setDuration(2000)
.setInterpolator(new DecelerateInterpolator());
}
我有两个活动之间的共享元素转换,其工作方式如下:
Intent someintent = new Intent(this, someclass.class);
if (Build.VERSION.SDK_INT >= 21) {
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this
, new Pair<>(viewClicked.findViewById(R.id.someimage), "someimage")
, new Pair<>(viewClicked.findViewById(R.id.someicon), "someicon")
);
startActivity(someintent, options.toBundle());
}
else {
startActivity(someintent);
}
这工作正常,但转换速度慢得令人痛苦。当第一次点击图像时,它似乎会在转换发生之前停顿一两秒钟。这是由于正在加载 activity 的 "weight" 还是延迟可配置?
您是否尝试更改 enterTransition
和 returntransition
的持续时间:
private Transition enterTransition() {
ChangeBounds bounds = new ChangeBounds();
bounds.setDuration(2000);
return bounds;
}
private Transition returnTransition() {
ChangeBounds bounds = new ChangeBounds();
bounds.setInterpolator(new DecelerateInterpolator());
bounds.setDuration(2000);
return bounds;
}
在onCreate
中:
getWindow().setSharedElementEnterTransition(enterTransition());
getWindow().setSharedElementReturnTransition(returnTransition());
另一种可能对某些已经在其样式中设置了转场效果的人有帮助的方法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getSharedElementEnterTransition().setDuration(2000);
getWindow().getSharedElementReturnTransition().setDuration(2000)
.setInterpolator(new DecelerateInterpolator());
}