I'm trying to check if some specific items are visible in the RecyclerView
; But I couldn't implement that. Please help me to determine if my items are completely visible in the RecyclerView
.
mrecylerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
LinearLayout ll = (LinearLayout) recyclerView.findChildViewUnder(dx, dy);
if (ll != null) {
TextureVideoView tvv = (TextureVideoView) ll.findViewById(R.id.cropTextureView);
}
}
});
I want to check if tvv
view is completely visible within the mrecyclerView
view.
You could make some logic using LayoutManager api to get last completely visible item position in RecyclerView onScrolled method:
((LinearLayoutManager) vYourRecycler.getLayoutManager()).findLastCompletelyVisibleItemPosition();
From the documentation: 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.
Try to use it and notify the RecyclerView adapter to refresh.
Note: i don't know why you're using findViewById in onScrolled method, this work should be implemented in RecyclerView ViewHolder for performance
you have to set LayoutManager
for RecyclerView
. if you are using most common LinearLayoutManager, then it have some methods for your purpose:
There are also similar methods in StaggeredGridLayoutManager, e.g. findFirstVisibleItemPositions
And general way would be to use bare LayoutManager
and its isViewPartiallyVisible method, but this probably needs more your code for particular use case
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With