innomotion media
innomotion media

Reputation: 922

Android, XAMARIN: Check if view is visible in a recyclerview and react to event

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

Answers (2)

tequila slammer
tequila slammer

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

Goku
Goku

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();



        }

    });

Upvotes: 1

Related Questions