Home > other >  How to set the portrait and landscape height (percent) in constraint layout but not losing the const
How to set the portrait and landscape height (percent) in constraint layout but not losing the const

Time:08-19

I did this code but the image pushed out the work space

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/constrainsalah"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/image1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintPortraitHeight_percent="0.15"
        app:layout_constraintLandscapeHeight_percent="0.2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">
</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

If I get your question correctly, Change the

app:layout_constraintPortraitHeight_percent="0.15"
app:layout_constraintLandscapeHeight_percent="0.2"

to

app:layout_constraintHeight_percent="0.2"

and add this on the line

app:layout_constraintVertical_bias="0.0" android:fillViewport="true"

Copy this code instead

<androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/constrainsalah"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/image1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHeight_percent="0.2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" android:fillViewport="true">
</androidx.constraintlayout.widget.ConstraintLayout>
  • Related