Android ConstraintLayout 使用 Space 控件创建间隔示例
"<androidx.constraintlayout.widget.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="match_parent">\n\n <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" />\n\n <Space android:layout_width="8dp" android:layout_height="8dp" app:layout_constraintEnd_toStartOf="@id/button2" app:layout_constraintStart_toEndOf="@id/button1" app:layout_constraintTop_toTopOf="@id/button1" />\n\n <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button 2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" />\n\n</androidx.constraintlayout.widget.ConstraintLayout>"\n\n在这个示例中,我们使用了 ConstraintLayout 作为根布局,并在其中放置了两个 Button 控件。我们使用 Space 控件在这两个 Button 之间创建了一个间隔。Space 控件的宽度和高度分别设置为 8dp,并使用了约束来确定其位置,使其位于第一个 Button 的右侧并与第二个 Button 对齐。\n\n通过使用 Space 控件,我们可以轻松地在 ConstraintLayout 中创建间隔和对齐效果,而无需使用额外的布局或空白视图。
原文地址: https://www.cveoy.top/t/topic/qx71 著作权归作者所有。请勿转载和采集!