1

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.

testivanivan
  • 967
  • 13
  • 36
  • 1
    Can you check this link, especially the comment on the answer to see if it applies to your case: https://stackoverflow.com/questions/46549516/keep-the-margin-when-the-referenced-view-is-gone-in-constraintlayout – ZivkoK Jan 14 '22 at 16:06
  • Not working in my case( – testivanivan Jan 14 '22 at 16:32
  • 1
    The margin gone is not for the ImageView. It should be on the TextView as `goneMarginTop` so the textview can say: if the view I'm constrained to on the TOP is GONE, then I will use this margin instead. – Martin Marconcini Jan 14 '22 at 16:34

0 Answers0