About NestedScrollView nested RecyclerView page always slides to the bottom when loading

If you don't understand the title, here are two pictures:
      

Under normal circumstances, what we expect is to display the left image effect after entering the page, but because the NestedScrollView nests the RecyclerView, the Recyclerview occupies the focus and the entire NestedScrollView content slides up. It's much easier to fix the bug once you know the cause.

Method 1: Set android:descendantFocusability=”blocksDescendants” in the root layout;

android:descendantFocusability 有三种值:

beforeDescendants:viewgroup会优先其子类控件而获取到焦点
afterDescendants:viewgroup只有当其子类控件不需要获取焦点时才获取焦点
blocksDescendants:viewgroup会覆盖子类控件而直接获得焦点

This method will cause the Editext focus in the page to be grabbed and unable to input, so the second method needs to be used.

Method 2: For pages with Editext, you need to use in the root layout:

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

Method 3: Use the first control at the top of NestedScrollView:

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

I find this approach a bit unreliable because sometimes it works and sometimes it doesn't. . . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324660966&siteId=291194637