ScrollView底部的空白区域

时间:2017-12-05 19:44:45

标签: android android-layout android-scrollview

我正在尝试使用ScrollView中的ConstraintLayout进行可滚动活动。

Supposed to be like this

但它在底部显示一个空白区域

Empty Space

在Android Studio上,Blueprint不显示任何内容。

我的XML是这样的:

<ScrollView 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="wrap_content"
android:clipToPadding="false"
android:layout_weight="1"
android:fillViewport="true">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.bonecadetrapo.imagensprincipal"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="25dp">

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

    <android.support.v7.widget.CardView
        android:id="@+id/cardview1"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/one" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 1" />

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

    <android.support.v7.widget.CardView
        android:id="@+id/cardview2"
        android:layout_width="164dp"
        android:layout_height="197dp"
        android:layout_marginBottom="300dp"
        android:layout_marginEnd="24dp"
        android:layout_marginStart="17dp"
        android:layout_marginTop="8dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.64"
        app:layout_constraintStart_toStartOf="@+id/guideline5"
        app:layout_constraintTop_toTopOf="@+id/guideline3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail2"
                android:layout_width="164dp"
                android:layout_height="170dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="3dp"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:scaleType="centerInside"
                app:srcCompat="@drawable/two" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail2"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="example 2" />

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

    <android.support.v7.widget.CardView
        android:id="@+id/cardview5"
        android:layout_width="164dp"
        android:layout_height="160dp"
        android:layout_marginBottom="170dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="24dp"
        android:clickable="true"
        android:elevation="3dp"
        android:focusable="true"
        android:foreground="?android:selectableItemBackground"
        app:layout_constraintBottom_toTopOf="@+id/guideline10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.039"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/cardview3"
        app:layout_constraintVertical_bias="0.0">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/thumbnail5"
                android:layout_width="164dp"
                android:layout_height="130dp"
                android:layout_marginLeft="6dp"
                android:layout_marginRight="6dp"
                android:layout_marginTop="6dp"
                android:adjustViewBounds="false"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:cropToPadding="false"
                android:scaleType="fitXY"
                app:srcCompat="@drawable/exampletwo" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_below="@id/thumbnail5"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="0dp"
                android:text="Example 2" />

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="384dp"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.Negocio">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.Negocio"
            app:title="Negocio">

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

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

    <android.support.constraint.Guideline
        android:id="@+id/guideline3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.06" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline5"
        android:layout_width="wrap_content"
        android:layout_height="929dp"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="204dp" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_end="17dp" />
</android.support.constraint.ConstraintLayout>

我正在使用Android Studio Beta 7和Oreo。 我已经尝试过google上的所有解决方案,但都没有。

1 个答案:

答案 0 :(得分:1)

我修复了它使用此代码

<ScrollView 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="wrap_content"
    android:clipToPadding="false"
    android:layout_weight="1"
    android:fillViewport="true">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:context="com.bonecadetrapo.imagensprincipal"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="25dp">

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

        <android.support.v7.widget.CardView
            android:id="@+id/cardview1"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/one" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 1" />

            </RelativeLayout>

            <android.support.constraint.Guideline
                android:id="@+id/guideline6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                app:layout_constraintGuide_end="17dp" />
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:id="@+id/cardview2"
            android:layout_width="164dp"
            android:layout_height="197dp"
            android:layout_marginBottom="300dp"
            android:layout_marginEnd="24dp"
            android:layout_marginStart="17dp"
            android:layout_marginTop="8dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.64"
            app:layout_constraintStart_toStartOf="@+id/guideline5"
            app:layout_constraintTop_toTopOf="@+id/guideline3"
            app:layout_constraintVertical_bias="0.0"
            android:layout_marginRight="24dp"
            android:layout_marginLeft="17dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail2"
                    android:layout_width="164dp"
                    android:layout_height="170dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginRight="3dp"
                    android:layout_marginTop="3dp"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:scaleType="centerInside"
                    app:srcCompat="@drawable/two" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail2"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="example 2" />

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

        <android.support.v7.widget.CardView
            android:id="@+id/cardview5"
            android:layout_width="164dp"
            android:layout_height="160dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="24dp"
            android:clickable="true"
            android:elevation="3dp"
            android:focusable="true"
            android:foreground="?android:selectableItemBackground"
            app:layout_constraintBottom_toTopOf="@+id/guideline10"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.039"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardview2"
            app:layout_constraintVertical_bias="0.0">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/thumbnail5"
                    android:layout_width="164dp"
                    android:layout_height="130dp"
                    android:layout_marginLeft="6dp"
                    android:layout_marginRight="6dp"
                    android:layout_marginTop="6dp"
                    android:adjustViewBounds="false"
                    android:background="?attr/selectableItemBackgroundBorderless"
                    android:clickable="true"
                    android:cropToPadding="false"
                    android:scaleType="fitXY"
                    app:srcCompat="@drawable/exampletwo" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_below="@id/thumbnail5"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:paddingTop="0dp"
                    android:text="Example 2" />

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="384dp"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:title="Negocio">

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

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

        <android.support.constraint.Guideline
            android:id="@+id/guideline3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.06" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline5"
            android:layout_width="wrap_content"
            android:layout_height="929dp"
            android:orientation="vertical"
            app:layout_constraintGuide_begin="204dp" />

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