Var*_*kar 7

希望这个例子可以帮助您理解这个简单的概念-

考虑2 TextViews与IDS textView1textView2其中textView2具有在年底0dp约束textView1

案例1:当能见度textView1VISIBLEtextView2会恰到好处的textView1与0dp保证金。

<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>
Run Code Online (Sandbox Code Playgroud)

结果-
在此处输入图片说明

案例2:当能见度textView1GONEtextView2会因为我已经指定其marginLeft设置为10dpapp: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>
Run Code Online (Sandbox Code Playgroud)

结果-
在此处输入图片说明