0

I am trying to implement a way to have my footer slide away down and my header to slide away up while user scrolls down the scrollview.

And vice-versa, as the user scrolls up the scollview, I want my footer to slide in from the bottom and the header slide in form the top.

Regarding the animation, I have found this good library https://github.com/daimajia/AndroidViewAnimations that comes with a lot of nice animations.

The closest example for what I am looking for, is the default Android Twitter application that makes it's footer disappear as the user scrolls his timeline down and makes it reappear as the user scrolls up.

By header, I am not talking about the Android Toolbar (op AppBar or whatever). It's a customed-made UI element that I want to animate while the user scrolls.

Same thing goes for the footer : it's a customed-made UI element.

While looking for solutions, I stumble upon this answer https://stackoverflow.com/a/28712465/3535408 but it does not work. Indeed, placing a Log.d inside the ifand else if shows that a simple touch with my finger triggers both a MotionEvent.ACTION_DOWN and a MotionEvent.ACTION_UP event. The same applies as I am sliding my finger up/down making the scrollview scrolls up/down : both events are triggered at the end when I stop touching the scrollview.

Is there a way to improve this solution ? Because as of now, as both MotionEvents are triggered, both animations are also triggered so the result is quite horrible.

Thanks !

Community
  • 1
  • 1
Mackovich
  • 3,319
  • 6
  • 35
  • 73

1 Answers1

1

An easy way to achieve that would be the following:

  • place the listview, the header and the footer inside a RelativeLayout
  • align the header with parent's top
  • align the footer with parent's bottom
  • add an empty header and footer to the listview with the same heights
  • catch the scrolling events on your listview and change the footer and/or header's translationY accordingly

But to answer your question, I'd say you should try a GestureDetector. It's way easier to manage the events - Detecting Gestures