协调器布局不会向上滚动特定位置

The Coordinator layout doesn't Scroll up for a specific position

我正面临有关滚动的协调器布局问题。对于特定位置,它不会滚动购买,单击 添加新 按钮后,列表元素将添加到下方。如果我们滚动该项目,协调器布局的行为通常就像展开和收缩一样。但是当我们尝试通过触摸布局向上滚动时

main.xml

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


<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cord"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:background="#4a90e2"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="#4a90e2"
        app:statusBarScrim="#4a90e2"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingTop="120dp"
            android:paddingBottom="40dp"
            android:layout_gravity="center|top"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Suzuki Swift !"
                android:textStyle="bold"
                android:textColor="@android:color/white"
                android:textSize="30dp"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:gravity="center"
                android:fontFamily="@font/latoregular"
                android:text="Some Text to enter about swift."/>

        </LinearLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

<include
    layout="@layout/test_one"/>

<ImageView
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:src="@drawable/man"
    android:layout_gravity="center|top"
    android:layout_marginTop="8dp"
    android:elevation="10dp"
    app:layout_behavior="@string/simple_view_behavior"
    app:behavior_dependsOn="@+id/app_bar"
    app:behavior_dependType="y"
    app:behavior_dependTarget="-176dp"
    app:behavior_targetX="16dp"
    app:behavior_targetY="8dp"
    app:behavior_targetWidth="40dp"
    app:behavior_targetHeight="40dp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="?attr/actionBarSize"
    android:text="Review For Swift"
    android:textSize="18dp"
    android:elevation="10dp"
    android:layout_marginLeft="72dp"
    android:layout_marginTop="-100dp"
    android:gravity="center_vertical"
    android:textColor="@android:color/white"
    android:alpha="0"
    app:layout_behavior="@string/simple_view_behavior"
    app:behavior_dependsOn="@+id/app_bar"
    app:behavior_dependType="y"
    app:behavior_dependTarget="-206dp"
    app:behavior_targetY="0dp"
    app:behavior_targetAlpha="1"/>

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

在 main.xml 中包含布局,即 test_one.xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/relative_layout"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff">
    <android.support.v7.widget.CardView
        android:id="@+id/cardOne"
        app:cardUseCompatPadding="true"
        app:cardElevation="4dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/linear_layout"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/linearLoutTwo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/linearLoutOne"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginTop="8dp">
            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <TextView
                    android:id="@+id/userName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:ellipsize="end"
                    android:fontFamily="@font/latoregular"
                    android:maxLines="1"
                    android:text="Review For Swift add attributes below,"
                    android:textColor="@color/titleColor"
                    android:textSize="15sp"
                    android:textStyle="bold"
                    app:layout_constraintStart_toStartOf="parent" />

                <EditText
                    android:id="@+id/editText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginTop="16dp"
                    android:background="@drawable/white_border_round"
                    android:fontFamily="@font/latolight"
                    android:hint="Eg: Looks,Speed"
                    android:padding="4dp"
                    android:paddingEnd="8dp"
                    android:paddingStart="8dp"
                    android:textColorHint="@color/titleColor"
                    android:textSize="16sp"
                    app:layout_constraintEnd_toStartOf="@+id/add_row_button"
                    app:layout_constraintHorizontal_bias="0.096"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/userName" />



                <Button
                    android:id="@+id/add_row_button"
                    android:layout_width="100dp"
                    android:layout_height="35dp"
                    android:layout_marginBottom="8dp"
                    android:layout_marginEnd="16dp"
                    android:layout_marginTop="8dp"
                    android:layout_weight="2"
                    android:background="@color/titleColor"
                    android:fontFamily="@font/latobold"
                    android:onClick="addRow"
                    android:text="Add"
                    android:textColor="@color/white"
                    android:textSize="12sp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintVertical_bias="0.0" />
            </android.support.constraint.ConstraintLayout>
        </LinearLayout>


    </LinearLayout>
    </android.support.v7.widget.CardView>
    <com.example.android.uidesigns.XmlClasses.InsertionListView
        android:id="@+id/listview"
        android:nestedScrollingEnabled="true"
        android:layout_below="@id/cardOne"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

list_item.xml

<android.support.v7.widget.CardView
    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_height="wrap_content"
    android:layout_width="match_parent"
    app:cardElevation="4dp"
    app:cardCornerRadius="4dp"
    app:cardUseCompatPadding="true">

<android.support.constraint.ConstraintLayout
    android:id="@+id/item_linear_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="horizontal">

    <!--<de.hdodenhof.circleimageview.CircleImageView-->
        <!--android:id="@+id/image_view"-->
        <!--android:layout_width="80dp"-->
        <!--android:layout_height="80dp"-->
        <!--android:layout_marginBottom="8dp"-->
        <!--android:layout_marginStart="18dp"-->
        <!--android:layout_marginTop="8dp"-->
        <!--android:gravity="center_vertical"-->
        <!--android:src="@drawable/man"-->
        <!--app:layout_constraintBottom_toBottomOf="parent"-->
        <!--app:layout_constraintStart_toStartOf="parent"-->
        <!--app:layout_constraintTop_toTopOf="parent" />-->



    <TextView
        android:id="@+id/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:gravity="center_vertical"
        android:text="Hello"
        android:textColor="#111"
        android:textSize="22sp"
        android:textStyle="bold"
        app:layout_constraintTop_toTopOf="parent" />

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

我添加了一张 Gif 来说明我的问题。请看一下。 ----->[用于理解的 gif]:https://i.stack.imgur.com/uSGfX.gif

终于找到解决方法了

我没有包括布局,而是将其写在 NestedScrollView 的同一个文件中。

不知何故它奏效了。谢谢您的帮助。

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