在Android中的某个位置停止滚动嵌套滚动视图

时间:2019-05-31 09:03:11

标签: java android android-scroll

我正在设计一个在嵌套滚动视图内具有两个嵌套滚动视图的UI。我无法在不干扰第二滚动视图的情况下在某一点停止第一嵌套滚动视图的滚动。

我尝试使用myNestedSrollView.scrollTo(0,guidline.getTop()),但它对当前的滚动模式没有任何更改。

这是我的布局设计:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
    tools:context=".MainActivity">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/svHead"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    app:cardBackgroundColor="#F09346"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:id="@+id/textView2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="50dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:text="Your 24/7 \nVirtual Care Team"
                            android:textAlignment="center"
                            android:textColor="#FFF"
                            android:textSize="30sp"
                            android:typeface="monospace"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="0.492"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="16dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:text="Get the care you need, on your schedule.\nAnytime, Anywhere"
                            android:textAlignment="center"
                            android:textColor="#FFF"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/textView2" />

                        <Button
                            android:id="@+id/button"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="16dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:layout_marginBottom="32dp"
                            android:background="#FFF"
                            android:paddingLeft="20dp"
                            android:paddingRight="20dp"
                            android:text="Get Care Now"
                            android:textColor="#F09346"
                            android:textSize="20sp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/textView3"
                            app:layout_constraintVertical_bias="0.275" />

                        <android.support.constraint.Guideline
                            android:id="@+id/guideline"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            app:layout_constraintGuide_begin="181dp" />
                    </android.support.constraint.ConstraintLayout>

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

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



        <android.support.v4.widget.NestedScrollView
            android:id="@+id/svMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/svHead">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    app:cardBackgroundColor="#29AFE0"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <TextView
                            android:id="@+id/textView4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="16dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:text="Talk to a \nDoctor Now"
                            android:textAlignment="center"
                            android:textColor="#FFF"
                            android:textSize="30sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView5"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:text="Get the care you need, on your schedule.\nAnytime, Anywhere"
                            android:textAlignment="center"
                            android:textColor="#FFF"
                            android:textSize="20sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/textView4" />

                        <Button
                            android:id="@+id/button2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:layout_marginBottom="8dp"
                            android:background="#FFF"
                            android:paddingLeft="20dp"
                            android:paddingRight="20dp"
                            android:text="Call A Doctor"
                            android:textColor="#29AFE0"
                            android:textSize="20sp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/textView5" />
                    </android.support.constraint.ConstraintLayout>

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView3"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="16dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cardView2">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/imageView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/textView7"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="12dp"
                            android:text="Personal Health Ally "
                            android:textColor="#585858"
                            android:textSize="18sp"
                            app:layout_constraintStart_toEndOf="@+id/imageView"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView8"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginBottom="8dp"
                            android:text="Connect with a health concierge to\nhelp navigate your healthcare, health\nplan and more"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toEndOf="@+id/imageView"
                            app:layout_constraintTop_toBottomOf="@+id/textView7"
                            app:layout_constraintVertical_bias="0.0" />
                    </android.support.constraint.ConstraintLayout>

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="4dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cardView3">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/imageView2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/textView9"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:text="Personal Health Ally"
                            android:textColor="#585858"
                            android:textSize="18sp"
                            app:layout_constraintStart_toEndOf="@+id/imageView2"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView10"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginBottom="12dp"
                            android:text="Connect with a health concierge to\nhelp navigate your healthcare, health\nplan and more"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toEndOf="@+id/imageView2"
                            app:layout_constraintTop_toBottomOf="@+id/textView9"
                            app:layout_constraintVertical_bias="0.0" />
                    </android.support.constraint.ConstraintLayout>

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView5"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/cardView4">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageButton
                            android:id="@+id/imageButton"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="16dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:layout_marginBottom="6dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintHorizontal_bias="0.5"
                            app:layout_constraintStart_toEndOf="@+id/imageButton2"
                            app:layout_constraintTop_toBottomOf="@+id/textView11"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <ImageButton
                            android:id="@+id/imageButton2"
                            android:layout_width="92dp"
                            android:layout_height="96dp"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="16dp"
                            android:layout_marginBottom="6dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintEnd_toStartOf="@+id/imageButton"
                            app:layout_constraintHorizontal_bias="0.5"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toBottomOf="@+id/textView11"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/textView11"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginEnd="8dp"
                            android:layout_marginRight="8dp"
                            android:text="Find Health Savings"
                            android:textColor="#585858"
                            android:textSize="20sp"
                            app:layout_constraintEnd_toEndOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent" />
                    </android.support.constraint.ConstraintLayout>
                </android.support.v7.widget.CardView>

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView6"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cardView5">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/imageView3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginBottom="8dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/textView12"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:text="Personal Health Ally "
                            android:textColor="#585858"
                            android:textSize="18sp"
                            app:layout_constraintStart_toEndOf="@+id/imageView3"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView13"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginBottom="8dp"
                            android:text="Connect with a health concierge to\nhelp navigate your healthcare, health\nplan and more"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toEndOf="@+id/imageView3"
                            app:layout_constraintTop_toBottomOf="@+id/textView12" />
                    </android.support.constraint.ConstraintLayout>

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cardView7"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="8dp"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintHorizontal_bias="1.0"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/cardView6">

                    <android.support.constraint.ConstraintLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <ImageView
                            android:id="@+id/imageView4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:layout_marginBottom="8dp"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toStartOf="parent"
                            app:layout_constraintTop_toTopOf="parent"
                            app:srcCompat="@mipmap/ic_launcher" />

                        <TextView
                            android:id="@+id/textView14"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginTop="8dp"
                            android:text="Personal Health Ally "
                            android:textColor="#585858"
                            android:textSize="18sp"
                            app:layout_constraintStart_toEndOf="@+id/imageView4"
                            app:layout_constraintTop_toTopOf="parent" />

                        <TextView
                            android:id="@+id/textView15"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginStart="8dp"
                            android:layout_marginLeft="8dp"
                            android:layout_marginBottom="8dp"
                            android:text="Connect with a health concierge to\nhelp navigate your healthcare, health\nplan and more"
                            app:layout_constraintBottom_toBottomOf="parent"
                            app:layout_constraintStart_toEndOf="@+id/imageView4"
                            app:layout_constraintTop_toBottomOf="@+id/textView14" />
                    </android.support.constraint.ConstraintLayout>

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


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

我希望svHeader滚动到准则为止,使“立即获取护理”按钮始终显示,而svMain保持原样滚动。

0 个答案:

没有答案