0

My recyclerview should open the first item closed. To this end, I wrote these lines.

 LinearLayoutManager llm = new LinearLayoutManager(getActivity());
 llm.scrollToPosition(1);
 paletteRecyclerView.setLayoutManager(llm);

I want to check if it is possible to scroll to position 1 fully. If my recyclerview is small I must open it without closing the first item. How can I check it?

Butterfly
  • 445
  • 1
  • 9
  • 22

2 Answers2

0

Try with below code...

LinearLayoutManager llm = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(llm);

RecyclerView.Adapter adapter = new YourAdapter();
recyclerView.setAdapter(adapter);

recyclerView.scrollToPosition(position);
Priyank Patel
  • 12,244
  • 8
  • 65
  • 85
0

I assume that you want to know if there are items to scroll in RecyclerView. So you can check as below after setting the adapter to the recyclerView.

recyclerView.post(new Runnable() {
        @Override
        public void run() {
            int recyclerViewheight = recyclerView.getHeight();
            int totalChildViewsHeight = recyclerView.computeVerticalScrollRange();
            if (recyclerViewheight > totalChildViewsHeight) {
                //there is no scroll (there are no more items to scroll)
            } else {
                //there is scroll (there are items to scroll)
            }
        }
    });
Akshay Bhat 'AB'
  • 2,690
  • 3
  • 20
  • 32