我刚刚编写了一个新的自定义转换,但我不确定如何完全定义它,因此可以在转换资源文件中使用,例如res/transition/rotate_transition.xml
:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="275"
android:interpolator="@android:interpolator/accelerate_decelerate"/>
以下是我的旋转转换代码:
public class Rotate extends Transition {
private static final String PROPNAME_ROTATION = "com.example.transition:rotate:rotation";
@Override
public void captureStartValues(TransitionValues transitionValues) {
captureValues(transitionValues);
}
@Override
public void captureEndValues(TransitionValues transitionValues) {
captureValues(transitionValues);
}
@Override
public Animator createAnimator(
ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
float startValue = (float) startValues.values.get(PROPNAME_ROTATION);
float endValue = (float) endValues.values.get(PROPNAME_ROTATION);
View view = endValues.view;
ValueAnimator animator = ValueAnimator.ofFloat(startValue, endValue);
animator.addUpdateListener(
animation -> {
float value = (float) animation.getAnimatedValue();
view.setRotation(value);
});
return animator;
}
private void captureValues(TransitionValues values) {
View view = values.view;
values.values.put(PROPNAME_ROTATION, view.getRotation());
}
}
我的问题是我应该初始化什么才能让这项工作得以实现,因为现在我只得到java.lang.RuntimeException: Unknown scene name: rotate
?