Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

margin end/right is not working on item in constraint layout

First see the layout for my point

enter image description here

Here is XML

 <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/mainCL"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/appBarLayout"
        >

        <TextView
            android:id="@+id/bankInfoHeadingTV"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="36dp"
            android:layout_marginTop="40dp"
            android:layout_marginEnd="8dp"
            android:fontFamily="@font/montserrat_semibold"
            android:text="Bank Information"
            android:textColor="@color/black"
            android:textSize="16sp"
            android:textStyle="bold"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/bankInfoIconIV"
            android:layout_width="42dp"
            android:layout_height="32dp"
            android:src="@drawable/card"
            app:layout_constraintBottom_toBottomOf="@id/bankInfoHeadingTV"
            app:layout_constraintStart_toEndOf="@id/bankInfoHeadingTV"
            app:layout_constraintTop_toTopOf="@id/bankInfoHeadingTV" />

    </androidx.constraintlayout.widget.ConstraintLayout>

I want to put some space between bankInfoHeadingTV and bankInfoIconIV.
So it put the margin of 30dp at the end of bankInfoHeadingTV but it is not working.
Margin start with bankInfoIconIV is working but why margin end with bankInfoHeadingTV is not working?

like image 668
Abdullah Ejaz Avatar asked Nov 02 '25 17:11

Abdullah Ejaz


1 Answers

You can only set margins for a view if you have the constraint. Because you constrained your ImageViews start to the end of textView you can set the start margin for the image. If you reversed it and constrained the end of yout TextView to the ImageView you can set the margin in the TextView.

like image 67
Gre3n Avatar answered Nov 05 '25 14:11

Gre3n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!