Scroll Dynamically added recycler view to position 0

20 views Asked by At

I have dynamically added n number of recycler views to linear layout. but each recycler view scrolls to end posion on each start up. i want them to show at position 0.

here's my code :

for(int i = 0; i < lists.size(); i++)     
{
            RecyclerView rv_scroll = new RecyclerView(this);
                rv_scroll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                rv_scroll.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
                MainRecyclerViewAdapter adapter = new MainRecyclerViewAdapter(this, item_data, new MainRecyclerViewAdapter.OnItemClickListener(){
                    @Override
                        public void onItemClick(Map<String, Object> item_data_2){
                            show_msg((String) item_data_2.get("title"));
                        }
                });
                rv_scroll.setAdapter(adapter);
                v_ll.addView(rv_scroll);
                rv_scroll.scrollToPosition(0);
                rv_scroll.smoothScrollToPosition(0);
}

I have dynamically added recycler view to dynamically added linear layout.

i have tried

rv_scroll.scrollToPosition(0);
rv_scroll.smoothScrollToPosition(0);
0

There are 0 answers