Moh*_*ahi -3 android android-layout android-view android-studio android-constraintlayout
app:layout_goneMarginLeft及其变体如何影响约束布局中的视图排列?
希望这个例子可以帮助您理解这个简单的概念-
考虑2 TextViews与IDS textView1和textView2其中textView2具有在年底0dp约束textView1。
案例1:当能见度textView1是VISIBLE,textView2会恰到好处的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:当能见度textView1是GONE,textView2会因为我已经指定其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)
| 归档时间: |
|
| 查看次数: |
604 次 |
| 最近记录: |