Detecting the scrolling direction in the adapter (up/down)
android, animation, direction, listview, scroll
Solution
This is the easiest and simplest method I came across. And it works like a charm.
view.addOnScrollListener(new View.OnScrollListener() {
@Override
public void onScrolled(@NonNull View view, int dx, int dy) {
if (dy > 0) {
//Scrolling down
} else if (dy < 0) {
//Scrolling up
}
}
});
Problem
I am trying to mimic the Google Plus application in my project, as it seems to be the reference now. The listview effect when scrolling is really nice and I would like to do something similar. I have started with the LayoutAnimationController http://android-er.blogspot.be/2009/10/listview-and-listactivity-layout.html ``` LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation( this, R.anim.list_layout_controller); getListView().setLayoutAnimation(controller); ``` and that seems bad, as not all the elements are animated: So I ended up by using the getView of the adapter and using this: ``` AnimationSet set = new AnimationSet(true); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(800); set.addAnimation(animation); animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,Animation.RELATIVE_TO_SELF, 0.0f ); animation.setDuration(600); set.addAnimation(animation); row.startAnimation(set); ``` The result is awesome and I am really happy with it! Unfortunately, it only works when I scroll from top to bottom of the list! I want to make it work when scrolling on the other side, I need to change a little bit the TranslateAnimation. So my question, is there a way to detect if I scroll upwards or downwards in my adapter?