嵌套的Recycler View滚动问题

时间:2016-09-07 08:51:48

标签: android android-recyclerview android-coordinatorlayout android-nestedscrollview

我使用了嵌套滚动视图内的Recycler View(在CoordinatorLayout中):

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/sections_recycler_view_linearlayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" />

            </RelativeLayout>

        </android.support.v4.widget.NestedScrollView>

在上述回收器的适配器中,我使用setNestedScrollingEnabled以编程方式添加了Child Recycler Views。

我的问题是: 当我滚动子回收器时,一旦滚动完成,父回收器就会滚动到顶部,就像我再次设置其适配器一样。我没有添加任何代码来通知适配器或滚动到最顶层的回收器项目或再次设置适配器。我无法弄清楚这种奇怪行为的原因。

任何帮助都将受到高度赞赏.. !!!

3 个答案:

答案 0 :(得分:0)

我在子回收器视图中显示进度条,直到我从服务器接收数据。一旦我获得数据,我就会填充它。我曾使用交错的适配器为行计数为2的儿童回收者,因此在填充数据后,我父母的回收者的身高正在发生变化。

我使用setHasFixedSize(false)作为父级回收者视图,因为它的高度正在变化,直到现在我还没有再看到这个问题。

答案 1 :(得分:0)

易, 添加

[root@box1 ~]# cat /etc/X11/xorg.conf
# nvidia-settings: X configuration file generated by nvidia-settings
# nvidia-settings:  version 384.69  (buildmeister@swio-display-x86-rhel47-06)  Wed Aug 16 20:54:53 PDT 2017

# nvidia-xconfig: X configuration file generated by nvidia-xconfig
# nvidia-xconfig:  version 384.69  (buildmeister@swio-display-x86-rhel47-06)  Wed Aug 16 20:57:01 PDT 2017

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "0"
EndSection

Section "Files"
    FontPath        "/usr/share/fonts/default/Type1"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/input/mice"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "LG Electronics W1643"
    HorizSync       30.0 - 50.0
    VertRefresh     57.0 - 63.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce GT 710"
EndSection

Section "Screen"

# Removed Option "metamodes" "1360x768 +0+0"
# Removed Option "metamodes" "1360x768_60 +0+0"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "Stereo" "0"
    Option         "nvidiaXineramaInfoOrder" "CRT-0"
    Option         "metamodes" "nvidia-auto-select +0+0"
    Option         "SLI" "Off"
    Option         "MultiGPU" "Off"
    Option         "BaseMosaic" "off"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection


Section "Extensions"
    Option "Composite" "Enable"
    Option "RANDR" "Enable"
EndSection

到你的NestedScrollview,你会很高兴。

答案 2 :(得分:0)

添加到您的父级回收站视图:

android:descendantFocusability="blocksDescendants"