Я хочу создать макет, как на картинке ниже:
Таким образом, каждая кнопка занимает 50% (родительская ширина - пространство для полей )
Если я установлю layout_constraintWidth_percent
на 0,5, это не сработает. Я могу добиться этого, используя LinearLayout
и вес, но как это сделать с ConstraintLayout
?
Вот схема, которую я использую:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<Button
android:id="@+id/other_options"
style="?tertiaryButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/half_pad"
android:text="@string/report_suicide_other_options_action"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<Button
android:id="@+id/yes"
style="?primaryButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/half_pad"
android:text="@string/action_yes"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/other_options"
/>
</androidx.constraintlayout.widget.ConstraintLayout>