简体   繁体   English

边距结束/右边不适用于约束布局中的项目

[英]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这是 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 .我想在bankInfoHeadingTVbankInfoIconIV之间放置一些空间。
So it put the margin of 30dp at the end of bankInfoHeadingTV but it is not working.所以它将 30dp 的边距放在bankInfoHeadingTV的末尾,但它不起作用。
Margin start with bankInfoIconIV is working but why margin end with bankInfoHeadingTV is not working?bankInfoIconIV开头的保证金有效,但为什么以bankInfoHeadingTV结尾的保证金无效?

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.因为您将 ImageViews 限制在 textView 的末尾,您可以设置图像的起始边距。 If you reversed it and constrained the end of yout TextView to the ImageView you can set the margin in the TextView.如果您反转它并将您的 TextView 的结尾限制为 ImageView 您可以在 TextView 中设置边距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM