I have one quiz layout in which I am using recyclerview
to show questions. I am using LinearLayoutManager
for the recyclerview
adapter. What I need is that whenever the user selects an option from the given questions, the next question should scroll to one position up (to the top of the layout). I tried to use different ways to get this but the problem is that scrolling occurs but it's not reaching to the top of the layout. It's scrolling in such way that the question and options are visible in the layout screen completely but not at the top it's showing in the down section. Code snippet in short
recyclerView = view.findViewById(R.id.recyclerView);
mLayoutManager = new LinearLayoutManager(context);
recyclerView.scrollToPosition(Qno+1);
// recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, new RecyclerView.State(), (Qno+1));
I tried both scrolltoposition and smoothscrolltoposition, but i am getting the same result.
Attaching the screenshot for the better explanation.
Here what I am getting after clicking any option on Q.5
This is what I am expecting, to load Q.6 in the top of the layout.