Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - RecyclerView to have first row (and values of row) always when I scrolling

I need to have first row(and values of row) always when I scrolling. I have a RecyclerViewI need that when I scrolling my recycle and when arrive Row eight to position of Row one I visible a TextView for shown a something, for example a Title. How I can mange it?

enter image description here

For example when yellow row arrive to position of row green I visible a TextView.

enter image description here

I don't know how I can get position first row of Layout from Activity.

NOTICE : I don't need to use libraries of GitHub. Thanks


1 Answers

first / last visible child depends on the LayoutManager. If you are using LinearLayoutManager or GridLayoutManager, you can use

int findFirstVisibleItemPosition();
int findFirstCompletelyVisibleItemPosition();
int findLastVisibleItemPosition();
int findLastCompletelyVisibleItemPosition();

For example:

GridLayoutManager layoutManager = ((GridLayoutManager)mRecyclerView.getLayoutManager());
int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
like image 193
cw fei Avatar answered Nov 28 '25 20:11

cw fei