2 years ago

#51913

test-img

testivanivan

Android. ConstraintLayout marginBottom not working

I hava ConstraintLayout with image and two text. I need to add goneMarginBottom for ConstraintLayout. Here is my code:

    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true">
     
    <ImageView  
                android:id="@+id/ivImage"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:src="@drawable/ic_test"           
                app:layout_constraintBottom_toTopOf="@id/tvTitle"
                app:layout_constraintDimensionRatio="1:1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_goneMarginBottom="40dp"
                tools:visibility="visible" />
    
            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:gravity="center"
                android:textColor="@color/black"
                android:textSize="14sp"          
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/ivImage"
                app:layout_constraintVertical_chainStyle="packed"  />
    
            <TextView
                android:id="@+id/tvMessage"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:gravity="center"
                android:textColor="@color/black"
                android:textSize="12sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/tvTitle" />
   </androidx.constraintlayout.widget.ConstraintLayout>

But when my image is gone the margin not apply for the view. Please, help, what may be wrong.

android

android-layout

constraints

android-constraintlayout

margins

0 Answers

Your Answer

Accepted video resources