【问题标题】:ScrollView does not show full content?ScrollView 不显示全部内容?
【发布时间】:2017-07-08 20:12:42
【问题描述】:

我有一个约束布局,其中我有一个 ImageView。我在我的 XML 中为我希望我的应用滚动浏览的一些 ImageButtons 放置了一个线性布局。我研究并发现我需要将我的线性布局包装在一个滚动视图中,但由于某种原因它不会显示我的内容的底部。它切断了模拟器中视图的底部。 我尝试将 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>

【问题讨论】:

  • @Selvin 我还是编程新手,所以你说的对我来说没有多大意义。如果你可以更具体,请做。

标签: android scrollview android-linearlayout android-constraintlayout


【解决方案1】:

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

Bottom of ScrollView clipped when using ConstraintLayout

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    相关资源
    最近更新 更多