У меня здесь проблема.Мне нужно было настроить пользовательские 4-флажки в центре линейного макета.Уже пробовал с гравитацией, layout_weight, настройкой гравитации внутри элемента XML.Однако кнопка всегда выровнена влево.Вот шаблон представления, который я реализовал:
<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"
tools:context="">
<TextView
android:id="@+id/tv_amount_tickets"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:text="@string/select_amount_tickets"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/til_amount_tickets"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:inputType="number"
android:imeOptions="actionDone"
android:maxLines="1"
android:hint="@string/amount_placeholder"
app:layout_constraintEnd_toEndOf="@+id/tv_amount_tickets"
app:layout_constraintStart_toStartOf="@+id/tv_amount_tickets"
app:layout_constraintTop_toBottomOf="@+id/tv_amount_tickets"
/>
<TextView
android:id="@+id/tv_ticket"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textSize="16sp"
android:textStyle="bold"
android:text="@string/tv_ticket_type"
app:layout_constraintEnd_toEndOf="@+id/til_amount_tickets"
app:layout_constraintStart_toStartOf="@+id/til_amount_tickets"
app:layout_constraintTop_toBottomOf="@+id/til_amount_tickets" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="@+id/tv_ticket"
app:layout_constraintStart_toStartOf="@+id/tv_ticket"
app:layout_constraintTop_toBottomOf="@+id/tv_ticket">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:foregroundGravity="center"
android:button="@drawable/checkbox_circle_check_selector" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:foregroundGravity="center"
android:button="@drawable/checkbox_circle_check_selector" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:foregroundGravity="center"
android:button="@drawable/checkbox_circle_check_selector" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:foregroundGravity="center"
android:button="@drawable/checkbox_circle_check_selector" />
</LinearLayout>
selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/checkbox_circle_check"
android:state_checked="false"/>
<item android:drawable="@drawable/checkbox_circle_check_selected"
android:state_checked="true"/>
<item android:drawable="@drawable/checkbox_circle_check"/>
обычный флажок
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp" />
<solid android:color="#FFFFFFFF" />
<stroke android:width="0.5dp" android:color="#FF8492A6"/>
</shape>
</item>
<item android:drawable="@drawable/ic_circle_check" />
установлен флажок
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="3dp"/>
<solid android:color="@color/colorPrimary"/>
<stroke android:width="0.5dp" android:color="#FF8492A6"/>
</shape>
</item>
<item android:drawable="@drawable/ic_circle_check_white" />