Why don't work Gravity center for Check Box

Viewed 113

I have a checkBox and set gravity center but the box doesn't come center

this is my XML file

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginTop="8dp"
    android:gravity="center"
    android:checked="false"
    android:clickable="false"
    app:buttonTint="@color/colorPrimary"
    android:scaleX="1.4"
    android:scaleY="1.4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

CheckBox image:

CheckBox image here

3 Answers

I myself solved this problem with style

first set the style attribute

android:theme="@style/checkBoxStyle"

Create a style

<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:textColorSecondary">@color/colorPrimary</item>
</style>

ConstraintLayout Chains Android developers recently released a new version of ConstraintLayout (1.0.2 as of today). This version contains a new major feature - Chains, which allows us to group views in ConstraintLayout.

Chains provide group-like behavior in a single axis (horizontally or vertically).

A set of widgets are considered a chain if they a linked together via a bi-directional connection

Once a chain is created, there are two possibilities:

Spread the elements in the available space A chain can also be "packed", in that case the elements are grouped together

Related