Reputation: 408
I am doing some chat application development and I am using recycler view to display the messages. The problem is I have Load Earlier Message Button at the top which always visible which I don't need. I need the button visible only when I scroll to top (first item of the list view which is available).Then when I press the load earlier button it will load earlier messages and button should become invisible. Again only when I scroll to the top of the recyclerView the button should visible. (This is something like WhatsApp load earlier message button example ).
Note: I can load the earlier messages only thing is how should make button visible when scroll to top and make it invisible after loading earlier messages.
Help me out guys!!!!!!!!!!!! Thanks in advance
Upvotes: 1
Views: 1004
Reputation: 4488
Seems like you need to use floating action button - check android design support library. But if you need it for Button with text you may do it with something like this for example.
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (linearLayoutManager.findFirstVisibleItemPosition() == 0) {
button.setVisibility(View.VISIBLE);
}
else {
button.setVisibility(View.GONE);
}
}
});
With android:animateLayoutChanges="true"
in parent viewgroup you will also see animation. Also you may try CoordinatorLayout with custom behavior for your button.
Upvotes: 5