app:layout_goneMarginLeft="" 对 constraintlayout 中的视图有何作用?

What does app:layout_goneMarginLeft="" do for views in constraintlayout?

app:layout_goneMarginLeft 及其变体如何影响 constraintlayout 中的视图排列?

例如,当您将视图 B 约束到另一个视图 A 时,并且在 logic/code 中的某个时刻,您将视图 A 的可见性更改为 view.GONE,如果例如,您使用 app:layout_goneMarginLeft="",它将保留边距或如文档中所述:

you can also indicate a different margin value to be used

你可以找到一个例子

这个概念的一个例子:

考虑具有 ID textView1textView22 TextViews,其中 textView2textView1 的末尾具有 0 dp 约束。

情况 1:当 textView1 的可见性为 VISIBLE 时,textView2 将恰好位于 textView1 的右侧,边距为 0 dp。

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/form_field_background"
        android:padding="5dp"
        android:text="TextView1"
        android:visibility="visible" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/form_field_background"
        android:padding="5dp"
        android:text="TextView2"
        app:layout_constraintStart_toEndOf="@+id/textView1"
        app:layout_goneMarginLeft="10dp"
        app:layout_goneMarginStart="10dp" />

</android.support.constraint.ConstraintLayout>

结果

情况 2:当 textView1 的可见性为 GONE 时,textView2 会将其 marginLeft 设置为 10 dp,因为我已指定 app:layout_goneMarginLeft="10dp"

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="100dp">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/form_field_background"
        android:padding="5dp"
        android:text="TextView1"
        android:visibility="gone" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/form_field_background"
        android:padding="5dp"
        android:text="TextView2"
        app:layout_constraintStart_toEndOf="@+id/textView1"
        app:layout_goneMarginLeft="10dp"
        app:layout_goneMarginStart="10dp" />

</android.support.constraint.ConstraintLayout>

结果