luka agdgomelashvili
luka agdgomelashvili

Reputation: 53

Constraint layout Guideline java.lang.AssertionError: BOTTOM

I have an ImageView and I want it to have height of the 40% of the screen height. I am trying to accomplish it by constraint layout's guidelines, but I get runtime error "java.lang.AssertionError: BOTTOM". I think the error is that image becomes higher than screen's 40%, but I don't know how to fix the bug. here is my xml code.

<ImageView
    android:id="@+id/apartment_main_image_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:src="@drawable/apart"
    app:layout_constraintBottom_toBottomOf="@+id/first_horizontal_guideline"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<androidx.constraintlayout.widget.Guideline
    android:id="@+id/first_horizontal_guideline"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintGuide_percent="0.4"/>

Upvotes: 0

Views: 823

Answers (4)

Rakshith Raksh
Rakshith Raksh

Reputation: 1

use layout constraint Height percent to set height and remove the bottom to bottom command or you need 40% of hegith so you can do it by constraint height percentage and make width match parent

For more info and clarification check out the link

Upvotes: 0

sourabh karmakar
sourabh karmakar

Reputation: 191

You didn't added the android:orientation="horizontal" attribute use this code

<androidx.constraintlayout.widget.Guideline
        android:id="@+id/first_horizontal_guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.40" />  

Upvotes: 0

Quick learner
Quick learner

Reputation: 11457

Use app:layout_constraintHeight_percent to set height according to screen and no need to use a guideline.

Example code

 <ImageView
    android:id="@+id/apartment_main_image_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:src="@drawable/apart"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintHeight_percent="0.4"
    app:layout_constraintTop_toTopOf="parent" />

Upvotes: 1

Mittal Patel
Mittal Patel

Reputation: 6089

This error is because you forgot to add the orientation of the Guideline You can give an orientation of the guideline according to your requirement horizontal or vertical

When you use a vertical guideline, any view constrained to it should do it horizontally and the same thing for horizontal guidelines.

<ImageView
    android:id="@+id/apartment_main_image_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:src="@drawable/apart"
    app:layout_constraintBottom_toTopOf="@+id/first_horizontal_guideline"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />


<androidx.constraintlayout.widget.Guideline
    android:id="@+id/first_horizontal_guideline"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent="0.4"/>

Upvotes: 1

Related Questions