【问题标题】:NestedScrollView and RecyclerView issues, how to separate them?NestedScrollView 和 RecyclerView 的问题,如何分开?
【发布时间】:2015-12-28 09:46:57
【问题描述】:

我不确定如何实现这个..我想使用:

  1. 折叠工具栏
  2. “正常”布局(NestedScrollView)
  3. RecyclerView
  4. 通过 NavigationDrawer 导航(因此布局在我的 activity_main.xml 中组合在一起)

当我尝试使用 RecyclerView 时出现问题 - 因为 NestedScrollView(是的,“不要将多个可滚动项放在一起”的规则是正确的)...

但是如何实现呢?是否有可能以某种方式保持布局分开?

信息:我在 FrameLayout 中替换应用程序的内容(见中间部分)。

插入多个 NestedScrollView(在每个 Fragment 中,应该是可滚动的)是否是一个合适的解决方案?

这是我的主要布局:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    android:background="@color/main_frame"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="192dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorPrimary"
            app:expandedTitleMarginBottom="32dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorPrimary"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax"
                />

            <include
                android:id="@+id/toolbar"
                layout="@layout/toolbar_overlay"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                />

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

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

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

        <FrameLayout
            android:id="@+id/main_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar"
            >
        </FrameLayout>

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

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

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_height="match_parent"
    android:layout_width="wrap_content"
    android:layout_gravity="start"
    android:background="@color/colorPrimaryNavDrawer"
    app:headerLayout="@layout/nav_drawer_header"
    app:menu="@menu/nav_drawer_items"
    />

提前致谢。

【问题讨论】:

    标签: android layout android-recyclerview nestedscrollview


    【解决方案1】:

    实现这一点的最佳方法是仅使用RecyclerView 和处理不同视图类型的适配器。 对于第一个适配器位置,列表项将是您在 NestedScrollView 中的固定内容一次,而对于其他位置,您要使用的是当前解决方案中的 RecyclerView 项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 2021-03-10
      • 2016-09-23
      • 1970-01-01
      相关资源
      最近更新 更多