Android animation shows up after delay

Viewed 97

I have a recyclerView and a 'View' in MotionLayout such that the View shows over recyclerView constrained to the bottom of the screen. I have onScrollListener added to the recyclerView such that when I scroll up the RecyclerView, the View hides. The code is like this:

RecyclerView recyclerView;
View v;
@Override
protected void onCreate(Bundle savedInstanceState)
{
//initialise views here

recyclerView.addOnScrollListener(new RecyclerView.onScrollListener(){
             @Override
             public void onScrolled (RecyclerView recyclerView, int dx, int dy)
            {  
                if(dy > 0)
                {
                    slideDown();
                  }
              else if(dy < 0)
              {
                  slideUp();
                }



            }


            @Override
            public void onScrollStateChanged (RecyclerView recyclerView, int newState)
            {
              }


});

}

public void slideUp()
{
  v.clearAnimation();
  ObjectAnimator.ofFloat(v, "ScaleY", 1 ).setDuration(200).start();  // to revert back


}

public void slideDown()
{
 v.clearAnimation();
  ObjectAnimator.ofFloat(v, "ScaleY", -1 ).setDuration(200).start(); //to hide back



}

I don't use BottomNavigationBehaviour here since I can't make it a child of Coordinator layout. I have also specified that View in motionlayout constraints.

Testing: When I scroll up the recyclerView, the slideDown animation starts only after the recyclerView has stopped scrolling. I don't want this behavoiur. If I change the code in slideDown() to set the View invisible without any animation, the view disappears as soon as I start scrolling; it doesn't wait for the recyclerView to stop.

This behaviour seems strange to me. Is there something I am missing?

0 Answers
Related