如何在 ConstraintLayout 中将一对视图居中?
How do I center a pair of Views inside a ConstraintLayout?
如何在 ConstraintLayout
中居中一对 Views
,如下所示, 没有嵌套 ?它们需要相互接触,并作为一个整体居中。
我尝试将它们彼此锚定并 parent 但后来它们没有相互接触,所以我为两者添加了水平偏差,但没有帮助。
提前致谢...
<ImageView
android:id="@+id/imageView"
android:layout_width="14dp"
android:layout_height="14dp"
android:scaleType="fitXY"
android:src="@drawable/checkmark"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_text"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@id/imageView"
app:layout_constraintRight_toRightOf="parent"/>
您需要为水平链左侧第一个 View
的链头设置 chainstyle 属性。将给出预期结果的样式是 packed
。在这种情况下不需要偏差。
<ImageView
android:id="@+id/imageView"
android:layout_width="14dp"
android:layout_height="14dp"
android:scaleType="fitXY"
android:src="@drawable/checkmark"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_text"
app:layout_constraintLeft_toRightOf="@id/imageView"
app:layout_constraintRight_toRightOf="parent"/>
如何在 ConstraintLayout
中居中一对 Views
,如下所示, 没有嵌套 ?它们需要相互接触,并作为一个整体居中。
我尝试将它们彼此锚定并 parent 但后来它们没有相互接触,所以我为两者添加了水平偏差,但没有帮助。
提前致谢...
<ImageView
android:id="@+id/imageView"
android:layout_width="14dp"
android:layout_height="14dp"
android:scaleType="fitXY"
android:src="@drawable/checkmark"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_text"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@id/imageView"
app:layout_constraintRight_toRightOf="parent"/>
您需要为水平链左侧第一个 View
的链头设置 chainstyle 属性。将给出预期结果的样式是 packed
。在这种情况下不需要偏差。
<ImageView
android:id="@+id/imageView"
android:layout_width="14dp"
android:layout_height="14dp"
android:scaleType="fitXY"
android:src="@drawable/checkmark"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/textView"/>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/some_text"
app:layout_constraintLeft_toRightOf="@id/imageView"
app:layout_constraintRight_toRightOf="parent"/>