I would like to align CheckBox
"symbol" to the top of its description.
What I have now:
What I want to have:
Current xml:
<CheckBox android:id="@+id/register_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/register_hint"/>
I've tried to achieve this by manipulating layout_gravity
attributes, but it doesn't work.
android:gravity="top"
will fix the problem:
<CheckBox android:id="@+id/register_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/register_hint" android:gravity="top"/>
Note that android:gravity
is different than android:layout_gravity
.
use
android:gravity="top" it will pin the box on top
use
padding_top="4dp" will adjust Text padding only (without changing box padding from top)
I found that:
android:gravity="fill"
works better than "top". Top wouldn't look right if the checkbox may also end up as only one line.
You can try this code:-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<layer-list>
<item android:top="2dp">
<bitmap android:gravity="center" android:src="@drawable/checkbox" />
</item>
</layer-list>
</item>
<item android:state_checked="true">
<layer-list>
<item android:top="2dp">
<bitmap android:gravity="center" android:src="@drawable/checkboxselected" />
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:top="2dp">
<bitmap android:gravity="center" android:src="@drawable/checkbox" />
</item>
</layer-list>
</item>
</selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With