RecyclerView scrolls to bottom when data is loaded

后端 未结 2 1281
鱼传尺愫
鱼传尺愫 2021-01-04 02:29

I have some weird issue with RecyclerView since I changed my app to load the data from Room database.

I have a screen (a Fragment

相关标签:
2条回答
  • 2021-01-04 03:15

    In my case this line was culprit,

    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, SPAN_COUNT, GridLayoutManager.VERTICAL, true);
    

    Specifically , last parameter which is setting reverseLayout attribute to true. Make it false and RecyclerView doesn't scroll to bottom of screen.

    0 讨论(0)
  • 2021-01-04 03:23

    Did you try this? Setting descendantFocusability property of parent RecyclerView to blocksDescendants.

    What this will do is, it will no more focus on your dynamically loaded child views inside recycler view, as a result, the automatic scroll will not take place.

    android:descendantFocusability="blocksDescendants"
    

    Note: The property descendantFocusability can be used with other views as well like FrameLayout, RelativeLayout, etc. So if you set this property to your parent/root layout, it will no more scroll to bottom.

    0 讨论(0)
提交回复
热议问题