嵌套的scrollview + recyclerview,奇怪的自动滚动行为 [英] nested scrollview + recyclerview, strange autoscroll behaviour

查看:200
本文介绍了嵌套的scrollview + recyclerview,奇怪的自动滚动行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在视图分页器中,我有几个片段,其中一个片段使用了带有标题和recyclerview的嵌套滚动视图:

In a view pager I have several fragments, one of them uses a nested scrollview with a header and a recyclerview :

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.m360.android.fragment.Members.MemberDetailsFragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="20dp">

        <header/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingTop="0dp" />

    </LinearLayout>

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

标签"header"表示一个复杂的布局,由于它扩展了很多代码,因此我不想在此处发布.

The tag "header" represents a complex layout that I didn't want to post here as it stretches out the code a lot.

当我在两个选项卡之间切换时,它将海峡滚动到回收者"视图.标头是隐藏的,我必须向上滚动才能看到它.

when I switch between the tabs, it scrolls strait to the recycler view. The header is hidden, I have to scroll up to see it.

关于什么原因的任何想法?如果可以避免,我不想在适配器中使用一种类型.

Any ideas on what causes that ? I don't wanna use a type in my adapter if I can avoid it.

推荐答案

我们有一个类似的问题.我们有一个垂直的RecyclerView.垂直RecyclerView的每个项目都包含水平RecyclerView,就像在Android TV应用中一样.

We have a similar problem. We have a vertical RecyclerView. Each item of this vertical RecyclerView contains an horizontal RecyclerView, like in the Android TV app.

当我们将支持库从23.4.0升级到24.0.0时,突然出现了自动滚动.特别是,当我们打开Activity然后返回时,垂直RecyclerView会向上滚动,以使当前的水平RecyclerView行不会被剪切,并且该行会完全显示.

When we upgraded the support libs from 23.4.0 to 24.0.0 the automatic scroll suddenly appeared. In particular, when we open an Activity and we then go back, the vertical RecyclerView scrolls up so that the current horizontal RecyclerView row does not get cut and the row is displayed completely.

添加android:descendantFocusability="blocksDescendants"可以解决此问题.

Adding android:descendantFocusability="blocksDescendants" fixes the issue.

但是,我找到了另一种解决方案,该方法也有效.在我们的情况下,垂直RecyclerView包含在FrameLayout内部.如果将android:focusableInTouchMode="true"添加到此FrameLayout,问题就消失了.

However, I've found another solution, which also works. In our case the vertical RecyclerView is contained inside a FrameLayout. If I add android:focusableInTouchMode="true" to this FrameLayout, the problem goes away.

这里甚至提到了第三个解决方案,该解决方案基本上是在子级/内部级setFocusable(false) > s.我还没试过.

There's even a third solution mentioned here, which basically consists on calling setFocusable(false) on the child/inner RecyclerViews. I haven't tryied this.

顺便说一下,AOSP上有一个公开问题.

By the way, there is an open issue on the AOSP.

这篇关于嵌套的scrollview + recyclerview,奇怪的自动滚动行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆