Reputation: 5025
I have a listview with multiple rows whose length could exceed the size of the screen of the smartphone. I want to be sure the user knows he has to keep scrolling down to see all the entries of the list.
So the first thing that came to my mind was to display a fuzzy and glowing arrow on the bottom of the screen (or just to make the bottom part of the listview glow) until the user starts scrolling down. How to display the arrow and set up its behavior?
Thanks.
Upvotes: 1
Views: 2380
Reputation: 4074
Try this code :
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int position = mLayoutManager.findFirstVisibleItemPosition();
if (newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
if (position == 0) {
imageViewDownArrow.setVisibility(View.VISIBLE);
} else {
imageViewDownArrow.setVisibility(View.GONE);
}
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
Upvotes: 1
Reputation: 677
You could display an ImageView
fixed on the bottom of your view. You can set it a fuzzy drawable if you want.
Add this to your layout.xml:
<ImageView
android:id="@+id/img_arrow"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true" />
And then in your code, you check when the list is scrolled if the last item has been drawn.
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if(totalItemCount != listView.getLastVisiblePosition() + 1){
imageView.setVisible(View.GONE);
}else{
imageView.setVisible(View.VISIBLE);
}
}
});
Upvotes: 3
Reputation: 544
Also to decide whether to show your button or not you can set a scroll listener on the listview and then call list.canScrollVertically(-1). If the returned value is true than you can show your button. If it is false it means that user can see all of the content without scrolling and you don't need to show your button.
Upvotes: 1