android - NestedScrollView Android 中的 RecyclerView

标签 android android-recyclerview android-design-library nestedscrollview

我正在尝试将 RecyclerView 放置在 NestedScrollView 中。问题是,如果我将 RecyclerView 放置在水平 LinearLayout 中,则会显示回收器 View 。但是,如果我将它放入 Vertical LinearLayout 中,它不会显示。这是我尝试过的东西:

<?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="true">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        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="?attr/colorPrimary"
            app:expandedTitleMarginBottom="32dp"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="80dp">
                <android.support.v7.widget.Toolbar
                    android:id="@+id/anim_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="20dp"
                    android:background="@color/AppBrightRed"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/ic_appicon"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="bottom|left" />
            </FrameLayout>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">
            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:name="com.google.android.gms.maps.MapFragment"
                app:layout_collapseMode="parallax" />
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:scrollbars="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:orientation="horizontal"
                android:layout_marginTop="10dp">
                <AutoCompleteTextView
                    android:layout_height="wrap_content"
                    android:layout_width="180dp"
                    android:hint="LOCATION"
                    android:id="@+id/ATView" />
                <Button
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="Checkin"
                    android:textColor="@color/AppBackground"
                    android:id="@+id/btnCheckin"
                    android:background="@color/AppBrightRed" />
                <android.support.v7.widget.RecyclerView ----DOES NOT SHOW IF PLACED HERE
            android:id="@+id/recyclerView"
            android:scrollbars="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
              </LinearLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

我该如何解决这个问题?

最佳答案

您可以使用 LinearLayout 代替 NestedScrollView:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        />

    </LinearLayout>

关于android - NestedScrollView Android 中的 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33513648/

相关文章:

java - 在 android Studio 上处理来自 AlertDialog 的 userInput

android - NestedScrollView 中 RecyclerView 的滚动问题

android - Android Studio-通过启动自动启动DDMS和模拟器,并在DDMS中自动清除logcat

android - RecyclerView 项目可绘制状态不工作

android - Realm 查询不更新我的适配器

android - 我的 FloatingActionButton 在 4.4 及更低版本上有一些奇怪的线条

android-layout - 持续查看 Bottom Sheet 单,覆盖最后一个 RecyclerView 项目

Android TabLayout固定模式但权重不同

java - 将数据从 Android 发送到笔记本电脑

android - 更改长点击延迟