为什么scrollview将按钮隐藏在其他视图后面?

时间:2019-08-15 18:21:48

标签: android xml android-layout android-constraintlayout android-scrollview

我在滚动视图中有一堆按钮,然后在滚动视图下面是一个水平线性布局,其中包含一些用于控件的按钮,然后在下面是一个Ad Mob横幅广告。我似乎无法弄清楚为什么当我滚动到按钮列表的底部时,最后一行按钮的大约一半隐藏在控件和横幅广告的后面。谁能告诉我如何使其滚动以显示完整的底部按钮行,以免它们隐藏在控件和广告横幅的线性布局后面?

以下是屏幕截图:

on the PhoneGap blog

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:fillViewport="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/button"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 1"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button2"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/button2"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 2"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <Button
                android:id="@+id/button3"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 3"

                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button2"
                app:layout_constraintTop_toBottomOf="@id/button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 4"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@id/button2" />

            <Button
                android:id="@+id/button5"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:text=" Button 5"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button2"
                app:layout_constraintTop_toBottomOf="@+id/button3" />

            <Button
                android:id="@+id/button6"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 6"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button4" />

            <Button
                android:id="@+id/button7"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:text=" Button 7"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button8"
                app:layout_constraintTop_toBottomOf="@+id/button5" />

            <Button
                android:id="@+id/button8"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 8"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button6" />

            <Button
                android:id="@+id/button9"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:text=" Button 9"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button10"
                app:layout_constraintTop_toBottomOf="@+id/button7" />

            <Button
                android:id="@+id/button10"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 10"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button8" />

            <Button
                android:id="@+id/button11"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:text=" Button 11"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button12"
                app:layout_constraintTop_toBottomOf="@+id/button9" />

            <Button
                android:id="@+id/button12"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 12"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button10" />

            <Button
                android:id="@+id/button13"
                android:layout_width="0dp"
                android:layout_height="0dp"

                android:text=" Button 13"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/button14"
                app:layout_constraintTop_toBottomOf="@+id/button11" />

            <Button
                android:id="@+id/button14"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:text="Button 14"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintDimensionRatio="H,1:1"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintLeft_toRightOf="@+id/button"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/button12" />

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                app:layout_constraintGuide_begin="87dp" />


        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/controlslayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        app:layout_constraintBottom_toTopOf="@+id/adView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <Button
            android:id="@+id/play"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Play/Pause" />

        <Button
            android:id="@+id/timer"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Timer" />

        <Button
            android:id="@+id/volume"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Volume" />
    </LinearLayout>

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:adSize="SMART_BANNER"
        app:adUnitId="ca-app-pub-3940256099942544/6300978111"
        app:layout_constraintBottom_toBottomOf="@+id/scrollView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"></com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>

当向下滚动时,底部的按钮应该完全可见,并且不要隐藏在其他视图的后面。

1 个答案:

答案 0 :(得分:0)

app:layout_constraintBottom_toBottomOf="parent"中的

ScrollView必须为app:layout_constraintBottom_toTopOf="@+id/controlslayout"。目前,您的列表正在填满整个屏幕,并在屏幕上方绘制按钮。

此外,如果您要像这样嵌套ViewGroup,那么使用ConstraintLayout并没有多大意义。