Recycler view inside NestedScrollView causes scroll to start in the middle

后端 未结 11 1006
眼角桃花
眼角桃花 2020-12-12 10:07

I am getting a weird scrolling behavior when I add a RecyclerView inside a NestedScrollView.

What happens is that whenever the scrollview has more rows than can be s

11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 10:40

    This problem arrives due to recycle view Focus.

    Automatically all focus gone to recycle view if its size extended the size of screen.

    adding android:focusableInTouchMode="true" to first ChildView like TextView, Button and so on(Not on ViewGroup like Linear, Relative and So on) make sense to solve the problem but API Level 25 and above solution doesn't work.

    Just add these 2 line in your ChildView like TextView, Button and So on (Not on ViewGroup like Linear, Relative and So on)

     android:focusableInTouchMode="true"
     android:focusable="true"
    

    I just faced this problem on API level 25. I hope other people don't waste time in this.

    For Smooth Scrolling On RecycleView add this line

     android:nestedScrollingEnabled="false"
    

    but adding this attiributes only works with API level 21 or above. If you want that smoothing scrolling work on below API level 25 then add this line in your class

     mList = findViewById(R.id.recycle_list);
     ViewCompat.setNestedScrollingEnabled(mList, false);
    

提交回复
热议问题