NestedScrollView和RecyclerView问题,如何将它们分开? [英] NestedScrollView and RecyclerView issues, how to separate them?

查看:84
本文介绍了NestedScrollView和RecyclerView问题,如何将它们分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm not sure how to implement this.. I want to use:

  1. 合拢工具栏
  2. 常规"布局(NestedScrollView)
  3. RecyclerView
  4. 通过NavigationDrawer导航(因此布局在我的activity_main.xml中合并在一起)
  1. Collapsing Toolbar
  2. "normal" Layout (NestedScrollView)
  3. RecyclerView
  4. and navigate by the NavigationDrawer (so the layouts come together in my activity_main.xml)

当我尝试使用RecyclerView时出现问题-由于NestedScrollView(是的,请勿将多个可滚动对象放在一起"的规则是正确的)...

The issues comes up when I try to use the RecyclerView - because of the NestedScrollView (yeah, the rule "don't place multiple scrollables together" is true)...

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

But how to achieve this? Is there a possibility to keep the layouts separated in some way?

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

Info: I am replacing the content of the app in the FrameLayout (see middle section).

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

Would it be a proper solution to insert multiple NestedScrollViews (in each Fragment one, which should be scrollable)?

这是我的主要布局:

<?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"
    />

谢谢.

推荐答案

实现此目的的最佳方法是仅将RecyclerView与带有适配器的适配器一起使用,以处理不同的视图类型. 对于第一个适配器位置,该列表项将成为您在NestedScrollView中的固定内容,对于其他位置,您要使用的是当前解决方案中的RecyclerView项目.

Best way to achieve this is to use only a RecyclerView with an adapter handling different view types. For the first adapter position, the list item will be your fixed content once in NestedScrollView, and for other positions what you want to use is the RecyclerView items from your current solution.

这篇关于NestedScrollView和RecyclerView问题,如何将它们分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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