首页 > 解决方案 > 回收站视图上方的 CardView,滚动为 One

问题描述

我正在尝试在回收站视图上方放置一个卡片视图。我想滚动我的卡片视图和回收器视图。问题是,只有回收器视图在滚动,并且回收器视图的内容在大小上非常扭曲。这就是我想要实现的目标: 示例图片

这是我的xml:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeFragment">

<!-- TODO: Update blank fragment layout -->

<android.support.v7.widget.CardView

    android:id="@+id/cardView"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:isScrollContainer="false"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginEnd="9dp"
        android:src="@drawable/background"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

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


<android.support.v7.widget.RecyclerView
    android:id="@+id/blogListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_constraintTop_toBottomOf="@+id/cardView" />

将不胜感激任何建议。

标签: javaandroidxmlandroid-recyclerview

解决方案


将您的recyclerviewandcardView放入 a 中scrollView,然后添加android:nestedScrollingEnabled="true"recycerlview

 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/frameLayout3"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- TODO: Update blank fragment layout -->
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


        <android.support.v7.widget.CardView

            android:id="@+id/cardView"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:isScrollContainer="false"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginEnd="9dp"
                android:src="@drawable/background"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/blogListView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:nestedScrollingEnabled="true"
            app:layout_constraintTop_toBottomOf="@+id/cardView" />

        </LinearLayout>

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

</android.support.constraint.ConstraintLayout>

推荐阅读