ScrollView不会滚动到android中的Bottom

时间:2017-03-12 11:12:30

标签: android android-scrollview android-constraintlayout android-nestedscrollview

我知道这个问题在这里已被多次询问过,但没有一个解决方案对我有所帮助。我确实尝试将边距更改为填充,然后滚动,但是我无法以正确的方式定位按钮。 这是xml:

<?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="@color/colorPrimary"
    android:scrollbars="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/about_us_toolbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/about_us_toolbar"
        app:layout_constraintVertical_bias="0.0"
        app:layout_constraintHorizontal_bias="0.0">

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

            <android.support.v7.widget.AppCompatImageView
                android:id="@+id/about_us_udaan_chakali"
                android:layout_width="0dp"
                android:layout_height="150dp"
                android:src="@drawable/udaan_wing"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/about_us_title"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Udaan"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:textSize="32sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/about_us_udaan_chakali"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/about_us_description"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:gravity="center"
                android:text="Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. "
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/about_us_title"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/about_us_connect"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="32dp"
                android:gravity="center"
                android:text="Connect with us"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/about_us_description"
                app:layout_constraintVertical_bias="0.0" />

            <View
                android:id="@+id/view"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="8dp"
                android:background="@color/colorPrimaryDark"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/about_us_connect"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/mail"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:scaleType="fitCenter"
                app:backgroundTint="@color/colorPrimary"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.21"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view"
                app:layout_constraintVertical_bias="0.0"
                app:srcCompat="@drawable/email" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/facebook"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginLeft="32dp"
                android:layout_marginStart="32dp"
                android:backgroundTint="@color/colorPrimary"
                android:scaleType="fitCenter"
                app:layout_constraintLeft_toRightOf="@+id/mail"
                app:layout_constraintTop_toTopOf="@+id/mail"
                app:srcCompat="@drawable/facebook_box" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/youtube"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginLeft="32dp"
                android:layout_marginStart="32dp"
                android:layout_marginTop="2dp"
                android:scaleType="fitCenter"
                app:backgroundTint="@color/colorPrimary"
                app:layout_constraintLeft_toRightOf="@+id/facebook"
                app:layout_constraintTop_toTopOf="@+id/facebook"
                app:srcCompat="@drawable/youtube_play" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/playstore"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:scaleType="fitCenter"
                app:backgroundTint="@color/colorPrimary"
                app:layout_constraintTop_toBottomOf="@+id/mail"
                app:srcCompat="@drawable/googleplay"
                android:layout_marginLeft="0dp"
                app:layout_constraintLeft_toLeftOf="@+id/mail"
                android:layout_marginRight="0dp"
                app:layout_constraintRight_toRightOf="@+id/mail" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/website"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:scaleType="fitCenter"
                app:backgroundTint="@color/colorPrimary"
                app:layout_constraintBottom_toBottomOf="@+id/playstore"
                app:layout_constraintTop_toTopOf="@+id/playstore"
                app:srcCompat="@drawable/web_link"
                android:layout_marginLeft="0dp"
                app:layout_constraintLeft_toLeftOf="@+id/facebook"
                android:layout_marginRight="0dp"
                app:layout_constraintRight_toRightOf="@+id/facebook" />

            <android.support.v7.widget.AppCompatImageButton
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginLeft="0dp"
                app:layout_constraintLeft_toLeftOf="@+id/youtube"
                app:layout_constraintBottom_toBottomOf="@+id/website"
                android:layout_marginBottom="0dp"
                android:layout_marginRight="0dp"
                app:layout_constraintRight_toRightOf="@+id/youtube"
                app:layout_constraintTop_toTopOf="@+id/website"
                android:layout_marginTop="0dp"
                android:src="@drawable/phone"
                android:backgroundTint="@color/colorPrimary"
                android:scaleType="fitXY"/>

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/about_us_reach"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="32dp"
                android:gravity="center"
                android:text="Reach Us"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/website"
                app:layout_constraintVertical_bias="0.0" />

            <View
                android:id="@+id/view_reach"
                android:layout_width="0dp"
                android:layout_height="1dp"
                android:layout_marginTop="8dp"
                android:background="@color/colorPrimaryDark"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/about_us_reach"
                app:layout_constraintVertical_bias="0.0" />

            <android.support.v7.widget.AppCompatImageButton
                android:id="@+id/map_view"
                android:layout_width="60dp"
                android:layout_height="60dp"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:scaleType="fitCenter"
                app:backgroundTint="@color/colorPrimary"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toRightOf="parent"
                app:layout_constraintRight_toLeftOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view_reach"
                app:layout_constraintVertical_bias="0.0"
                app:srcCompat="@drawable/google_maps" />

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="BVM Engineering College, Opp, Shastri Maidan, Mota Bazaar, Vallabh Vidhyanagar, Anand, Gujarat 388120, India"
                android:textAlignment="center"
                android:textColor="@color/colorWhite"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/map_view"
                app:layout_constraintVertical_bias="0.0" />
        </android.support.constraint.ConstraintLayout>

    </ScrollView>
</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:1)

仔细观察工具栏代码:

<android.support.v7.widget.Toolbar
        android:id="@+id/about_us_toolbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

输出1:

enter image description here

查看工具栏上的4个约束:

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"

这会导致工具栏在父级内居中。由于滚动视图被限制在工具栏下方,因此在滚动顶部触及顶部工具栏后,它无法滚动所有内容。

删除此约束:

app:layout_constraintBottom_toBottomOf="parent"

现在您的新工具栏代码为:

<android.support.v7.widget.Toolbar
            android:id="@+id/about_us_toolbar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

输出2:

enter image description here