【问题标题】:Scrolling RecyclerView and siblings in a Viewpager, in a CoordinatorLayout在 CoordinatorLayout 中,在 Viewpager 中滚动 RecyclerView 和兄弟姐妹
【发布时间】:2015-11-28 11:41:30
【问题描述】:

我正在尝试使用以下结构实现视图

MainActivity
    CoordinatorLayout
        ViewPager
            Fragment (root view, RelativeLayout)
                TextView
                RecyclerView

或者,有一个 RecyclerView 和一个 Fragment 中的兄弟,放置在一个 ViewPager 中,在一个 CoordinatorLayout 中。

在这个视频中可以看到布局,以及问题:https://youtu.be/1oAqEpg7N4I

我希望 TextView 与 RecyclerView 一起滚动,但是 TextView 当前保持在原位,而 RecyclerView 在其下方自行滚动。您可以在视频中看到效果。

我找到了在 ViewPager 中处理 RecyclerView 的演示,但我找不到任何像我一样使用标题的演示。

我尝试引入一个 NestedScrollView 作为 Viewpager 的父级,作为片段布局的根,而 ScrollView 只能有一个父级,所以我无法添加它来包装 TextView 和 RecyclerView。

这是我的 CoordinatorLayout 实现。如果需要,可以在 Github 以及 https://github.com/vidia/MaterialDiningCourts/blob/master/app/src/main/res/layout/activity_meal_view.xml 上找到它以获取上下文。

<android.support.design.widget.CoordinatorLayout 
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            ...
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/AppTheme.PopupOverlay">
            ...
        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:foregroundGravity="top"
            ... />
    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

    标签: android android-layout android-fragments android-appcompat


    【解决方案1】:

    为什么不将您的文本视图放在您的回收站视图中,以便它与您的 viewpager 中的回收站视图的内容一起滚动?

    【讨论】:

    • 我在想这个。但这对我来说似乎是一个黑客行为。 recyclerview 应该只包含列表 IMO,它不应该包含我的标题。不过,TI 可能会这样做,但我不会说这是一个好的解决方案。
    猜你喜欢
    • 2019-05-06
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    相关资源
    最近更新 更多