Created
January 19, 2018 18:14
-
-
Save ar-android/58e60b23ff1e51f69e08a22cd6466038 to your computer and use it in GitHub Desktop.
Show and Hide Floating Action Button when scrolling recyclerview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Java | |
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | |
@Override | |
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { | |
super.onScrolled(recyclerView, dx, dy); | |
if (dy > 0 && fab.getVisibility() == View.VISIBLE) { | |
fab.hide(); | |
} else if (dy < 0 && fab.getVisibility() != View.VISIBLE) { | |
fab.show(); | |
} | |
} | |
}); | |
// Kotlin | |
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { | |
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) { | |
super.onScrolled(recyclerView, dx, dy) | |
if (dy > 0 && fab.visibility === View.VISIBLE) { | |
fab.hide() | |
} else if (dy < 0 && mFloatingActionButton.visibility !== View.VISIBLE) { | |
fab.show() | |
} | |
} | |
}) |
Hey, "addOnScrollListener" are depecrated, what's the alternative ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great thanks