当 Recyclerview 在 NestedScrollview 中时自动启动视频

Autostarting of Video when Recyclerview is inside NestedScrollview

我在 NestedScrollview 中有一个 recyclerview。 recyclerview 加载图像和视频。图像没有问题。但是我已经为视频应用了一些名为 Toroplayer 的库,当它获得焦点时自动启动。现在,在仅使用 recyclerview 的同时,加载在其中的视频得到了关注,因此开始如预期。但是当我在 Recyclerview 上使用 NestedScrollview 时,视频没有获得焦点,因此不会自动启动(这就是我认为问题的原因。我可能错了。但是当我将 videoview 放在 Nestedscrollview 之外时视频自动启动。)我需要使用 Nestedscrollview,不能忽略它。

这是XML的部分:

<android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/swipe_refresh_layout"

        android:layout_marginTop="8dp"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">


        <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:fillViewport="true"
        android:overScrollMode="never"
            android:id="@+id/hometimeline"
            app:layout_behavior="com.evs.demo.layout.FixedScrollingViewBehavior">



                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    >


                    <android.support.v7.widget.RecyclerView
                        android:layout_width="match_parent"
                        android:layout_height="80dp"
                        android:layout_marginTop="1dp"
                        android:background="#fff"
                        android:id="@+id/statusView"
                        android:orientation="horizontal"
                        android:layout_marginStart="4dp"
                        android:layout_marginEnd="4dp"
                        android:layout_marginBottom="2dp"
                        />

                    <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        app:cardElevation="18dp"

                        >

                        <im.ene.toro.widget.Container
                            xmlns:android="http://schemas.android.com/apk/res/android"
                            android:id="@+id/home_blog_list"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_marginStart="14dp"
                            android:layout_marginEnd="14dp"
                            android:nestedScrollingEnabled="false"
                            app:layoutManager="LinearLayoutManager"
                            app:layout_behavior="@string/appbar_scrolling_view_behavior"
                            />

                    </android.support.v7.widget.CardView>




                </LinearLayout>



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


        </LinearLayout>


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

由于 toroplayer(我正在使用的视频播放器库)开始聚焦,我需要有一种方法让 recyclerview 中的 childred 获得对 nestedscrollview 的聚焦。

尝试加入回收站

recyclerView.setNestedScrollingEnabled(false);

What's the alternative?

对于这个您不想依赖 NestedScrollView 的问题,"natural" 替代方法 是使用 RecyclerView 的 ViewType 参数并根据在你的内容上。因此,由于 RecyclerView,整个事情都可以滚动,并且一切正常。但这需要做更多的工作,因为您必须为所有不同的内容创建视图类型并准备列表,以便 RecyclerView 收到一个格式良好的常见项目列表,该列表可以描述您需要显示的内容。这是更多的工作,但一旦你开始工作,它就非常可靠。

查看您的布局,您具有以下层次结构:

<SwipeRefresh>
  <LinearLayout>
     <NestedScrollView>
        <LinearLayout>
            <RecyclerView />
            <CardView>
               <toro.widget.Container />
            </CardView>
        </LinearLayout>
      </NestedScrollView>
   </LinearLayout>
</SwipeRefresh>

如果我不需要使用 NestedScrollView,我会使用 Constraint Layout 将其展平。我理解您的布局的方式是,您的 recyclerview 具有固定的 80dp 高度,并且在您下方安装了这个 carview,它有一个容器(视频播放器?),固定在底部。

你提到你需要使用 NestedScrollView,我不知道为什么,但是 如果你出于某种原因意识到你不需要它,我就是这样d 实施布局:

<SwipeRefresh>
   <ConstraintLayout>
      <RecyclerView />
      <CardView>
         <Toro Container>
      </CardView>
    </ConstraintLayout>
</SwipeRefresh>

在此,滑动将包含 ConstraintLayout,它将使用整个屏幕提供 by/to 滑动布局,RecyclerView 将位于顶部 80dp 的高度,接下来是 CardView,使用所有剩余的 space 和 Toro Container 内部也将使用与给定的 CardView 一样多的 space。

如果您可能阐明了为什么需要 NestedScrollView,那么也许我们可以重新考虑这一点,但除此之外,如果您确实需要 Nesting,那么您将需要播放(并可能扩展 NestedScrollView)以查看点击这些子项时焦点在做什么。调试焦点所在的位置,然后从那里开始。 :/