In my application I use a bottom sheet (from the support library) which works great. Now I would like to animate a layout change while the sheet is dragged up. For this I have created a subclass of BottomSheetCallback
(this is normaly an inner class of a Fragment so not all objects used in this calss are initialized here):
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; } }
As you can see I also created two Scene
from different layout files and a custom Transition
to animate between the scenes with the TransitionManager
. My problem is that the Transition
should be based on the slideOffset
parameter (in range of 0-1) but the TransitionManager
uses the Animation
class in the background which is normally time based in Android.
I tried to create the custom Intapolator but this does not work properly. So how can I create a Transition
which is based on an external variable and not on time?
0 comments:
Post a Comment