虽然看起来很简单,但我无法做到,我希望这两个按钮能够从它们的侧边相接并水平居中,如下图所示:
我试过了这个线程中的答案:Center two buttons horizontally,但它仅适用于RelativeLayout而不是ContrainstLayout。
我还尝试过进行调整。
但是没有成功。我的无用的xml文件:
使用ConstraintLayout能否实现这一点?
我还尝试过进行调整。
app:layout_constraintHorizontal_chainStyle="spread"
但是没有成功。我的无用的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:background="@color/btnTrue"
android:text="Button"
android:textColor="#ffffff"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
style="@style/btnStyle"
android:layout_height="wrap_content"
android:layout_marginEnd="56dp"
android:background="@color/btnFalse"
android:text="Button"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
使用ConstraintLayout能否实现这一点?