简体   繁体   English

CardView在Recycler视图上方,滚动为一个

[英]CardView above Recycler view,Scroll as One

I'm trying to place a card view above a recycler view. 我正在尝试将卡片视图放在回收者视图上方。 I Would like to scroll my card view and recycler view as one. 我想将卡片视图和回收者视图作为一个滚动。 The problem is, only the recycler view is scrolling and the contents of the recycler view are quite distorted in size. 问题是,只有“回收者”视图在滚动,并且“回收者”视图的内容在大小上相当不正确。 This is what I'm trying to achieve: Example Image 这是我要实现的目标: 示例图像

Here's my xml: 这是我的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" />

Would Appreciate any suggestions. 将不胜感激任何建议。

Put your recyclerview and cardView in a scrollView , and add android:nestedScrollingEnabled="true" in recycerlview 将您的recyclerviewcardView放入scrollView ,并在scrollView添加android:nestedScrollingEnabled="true"

 <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>
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF">

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="15dp"
        tools:layout_editor_absoluteY="50dp">

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbarSize="1sp">
            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:paddingBottom="50dp">

                <TextView
                    android:id="@+id/TextView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="5dp"
                    android:text="TextView"
                    app:fontFamily="@font/proximanova_regular" />

                <EditText
                    android:id="@+id/EditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ems="10"
                    android:inputType="numberDecimal"
                    app:fontFamily="@font/proximanova_regular" />

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:nestedScrollingEnabled="true" />
            </LinearLayout>
            </android.support.v4.widget.NestedScrollView>
        </ScrollView>
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM