В моем приложении я использую нижний лист (из библиотеки поддержки), который отлично работает. Теперь я хотел бы оживить изменение макета, пока лист перетаскивается. Для этого я создал подкласс BottomSheetCallback
(это нормальный внутренний класс фрагмента, поэтому здесь не все объекты, используемые в этих calss):
public class MyBehavior extends BottomSheetBehavior.BottomSheetCallback {
Transition transition;
float lastOffset = 0;
Scene scene;
public PlayerBehavior() {
TransitionInflater inflater = TransitionInflater.from(getContext());
transition = inflater.inflateTransition(R.transition.player);
//transition.setDuration(300);
scene = fullLayout;
transition.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float v) {
return lastOffset;
}
});
}
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if(newState == BottomSheetBehavior.STATE_DRAGGING) {
TransitionManager.go(scene, transition);
}
}
@Override
public void onSlide(View bottomSheet, final float slideOffset) {
scene = (slideOffset > lastOffset) ? smallLayout : fullLayout;
lastOffset = slideOffset;
}
}
Как вы можете видеть, я также создал два Scene
из разных файлов макета и пользовательский Transition
для анимации между сценами с помощью TransitionManager
. Моя проблема заключается в том, что Transition
должен быть основан на параметре slideOffset
(в диапазоне от 0 до 1), но TransitionManager
использует класс Animation
в фоновом режиме, который, как правило, основан на времени в Android.
Я попытался создать пользовательский Intapolator, но это не работает должным образом. Итак, как я могу создать Transition
, который основан на внешней переменной, а не во времени?