ScrollView没有显示完整内容?

时间:2017-07-08 20:12:43

标签: android scrollview android-linearlayout android-constraintlayout

我有一个Constraint Layout,其中有一个ImageView。我在我的XML下面放了一个线性布局,对于一些想要我的应用滚动的ImageButtons。我研究并发现我需要将我的线性布局包装在我所做的ScrollView中,但由于某种原因它不会显示我的内容的底部。它在模拟器中切断了视图的底部。 我尝试将ScrollView包装在一个相对布局中,这是在一个论坛中提出但没有做任何事情。我也尝试使用android:fillViewport =“true”设置ScrollView,但这也不起作用。我将附上它看起来像的屏幕截图,我将在下面粘贴XML。

screenshot of app with content not showing at bottom

<?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"
tools:context="com.autismacademyed.www.autismacademy.AutismAcademy">


<ImageView
    android:id="@+id/imageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/logo" />


<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintTop_toBottomOf="@+id/imageView2">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="0dp"
        android:orientation="vertical"
        android:scrollIndicators="right|end"
        android:scrollbars="vertical"
        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/imageView2"
        app:layout_constraintVertical_bias="0.0">

        <ImageButton
            android:id="@+id/imageButtonRed"
            android:layout_width="104dp"
            android:layout_height="124dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:background="@null"
            android:onClick="imageButtonOnClick"
            android:scaleType="centerCrop"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageButtonYellow"
            app:srcCompat="@drawable/ic_action_red" />

        <ImageButton
            android:id="@+id/imageButtonBlue"
            android:layout_width="125dp"
            android:layout_height="110dp"
            android:layout_marginTop="8dp"
            android:background="@null"
            android:scaleType="centerCrop"
            app:layout_constraintTop_toBottomOf="@+id/imageButtonRed"
            app:srcCompat="@drawable/ic_action_blue"
            tools:layout_editor_absoluteX="0dp" />

        <ImageButton
            android:id="@+id/imageButtonYellow"
            android:layout_width="109dp"
            android:layout_height="125dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@null"
            android:onClick="imageButtonOnClick"
            android:scaleType="centerCrop"
            android:visibility="visible"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView2"
            app:srcCompat="@mipmap/ic_yellowpuzzlepiece" />

        <ImageButton
            android:id="@+id/imageButtonGreen"
            android:layout_width="109dp"
            android:layout_height="125dp"
            android:background="@null"
            android:scaleType="centerCrop"
            app:layout_constraintTop_toBottomOf="@+id/imageButtonYellow"
            app:srcCompat="@drawable/ic_action_green" />


        <ImageButton
            android:id="@+id/imageButtonBrown"
            android:layout_width="109dp"
            android:layout_height="125dp"
            android:background="@null"
            android:scaleType="centerCrop"
            app:layout_constraintTop_toBottomOf="@+id/imageButtonYellow"
            app:srcCompat="@drawable/ic_action_green" />

    </LinearLayout>

</ScrollView>

</android.support.constraint.ConstraintLayout>

1 个答案:

答案 0 :(得分:0)

因此,在对此论坛网站进行了大量研究并通过视频教程后,我决定发布此问题。我很抱歉浪费别人的时间,但我注意到左边的相关问题!我找到了一篇与我的布局相似的文章,在阅读时我理解了如何解决自己的问题!我搞乱了代码并从我的XML中删除了线性布局,并将其替换为另一个Constraint布局。我还将fillViewPort代码行添加到ScrollView,并删除了Layout Width和Height,并将其更改为0dp。我使用约束选项让ScrollView在模拟器中正确匹配,我为ImageButtons做了相同的事情,使它们能够正确地对齐。我将链接帮助我的文章!

Bottom of ScrollView clipped when using ConstraintLayout