Reputation: 922
I have a recyclerview with some elements in it. Some of which are supposed to start a little animation once they become visible.
In an activity with a scollview, I simply overrode "OnWindowFocusChange(Bool hasFocus)"
to check for visibility. However, this doesnt exist in a recview.
How would I do this in a recyclerview?
Thanks :)
Upvotes: 0
Views: 247
Reputation: 2879
You can add a OnScrollListener like this:
_myRecyclerView.AddOnScrollListener(new MyOnScrollListener());
Your custom listener can be implemented like @Prem showed in Java.
public class MyOnScrollListener : RecyclerView.OnScrollListener
{
public override void OnScrolled(RecyclerView recyclerView, int dx, int dy)
{
//rest of the code
}
}
Upvotes: 1
Reputation: 9732
Try this use RecyclerView.addOnScrollListener
RecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int firstpos = horizontalLayoutManager.findFirstCompletelyVisibleItemPosition();
int lastpos = horizontalLayoutManager.findLastCompletelyVisibleItemPosition();
}
});
int findFirstCompletelyVisibleItemPosition ()
Returns the adapter position of the first fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.
int findLastCompletelyVisibleItemPosition ()
Returns the adapter position of the last fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.
Upvotes: 1