Reputation: 117
How to hide/show view when scrolling up/down android like Foodpanda
app
I want to hide/show view (linear or relative layout) when ScrollView
is up/down like this above gif.
But my app I do not use Recyclerview or list view (just textview).
How can I create it?
Thanks!
Upvotes: 8
Views: 8213
Reputation: 146
You need to add in CollapsingToolbarLayout:
app:layout_scrollFlags="scroll|enterAlways|snap"
and you will get behavior that you need. Hide view when scroll up and show view when scroll down
Upvotes: 0
Reputation: 11487
Add scroll listener to the RecylerView
If the user is scrolling down - then start translation animation UPWARDS
If the user is scrolling up - then start translation animation DOWNWARDS
Anim translation UPWARDS:- (trans_upwards.xml)
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="100%p"
android:duration="300"
/>
</set>
Anim translation DOWNWARDS:-(trans_downwards.xml)
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:duration="300"
/>
</set>
Add scroll listener to recyclerView (and also do a checking)
boolean check_ScrollingUp = false;
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (dy > 0) {
// Scrolling up
if(check_ScrollingUp)
{
YourView.startAnimation(AnimationUtils.loadAnimation(context,R.anim.trans_downwards));
check_ScrollingUp = false;
}
} else {
// User scrolls down
if(!check_ScrollingUp )
{
YourView
.startAnimation(AnimationUtils
.loadAnimation(context,R.anim.trans_upwards));
check_ScrollingUp = true;
}
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
Upvotes: 10