0

我有一個約束佈局,在那裏我有一個ImageView。我在我的XML下面放置了一個線性佈局,用於我希望我的應用程序滾動瀏覽的一些ImageButton。我研究並發現,我需要將我的線性佈局封裝在ScrollView中,但由於某種原因,它不會顯示我的內容的底部。它切斷了仿真器中視圖的底部。 我試圖在一個相對佈局中包裝ScrollView,這是在其中一個論壇中建議的,但是什麼也沒做。我也試着用android:fillViewport =「true」來設置ScrollView,但那也沒用。我將附上它看起來像的屏幕截圖,我將在下面粘貼XML。ScrollView不顯示完整內容?

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> 
+0

@Selvin我還是編程新手,所以你說的話對我來說沒有多大意義。如果你可以更具體地請做。 – ZachGiovanelli

回答

0

因此,在這個論壇裏,並通過視頻教程做了相當多的研究之後,我決定發佈這個問題。我很抱歉浪費別人的時間,但我注意到左邊的相關問題!我發現一篇文章與我的佈局非常相似,閱讀時我明白如何解決我自己的問題!我搞砸了代碼,並從我的XML中刪除了線性佈局,並用另一個約束佈局替換它。我還將fillViewPort代碼行添加到ScrollView,並刪除了Layout Width和Height,並將其更改爲0dp。我使用約束選項讓ScrollView在模擬器中正確匹配,並且我爲ImageButton做了相同的事情,以便相互對齊。我會鏈接幫助我的文章!

Bottom of ScrollView clipped when using ConstraintLayout