Reputation: 167
I have made a custom checkbox where checkbox text would be in left side and checked mark in the right side. My custom checkbox works perfectly but facing on problem. That is, my checkbox text is not aligning exactly to left. There is some space in the left. My code is.
<CheckBox
android:id="@+id/chk_1"
android:text="DHKXXX"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:drawableRight="@xml/custom_checkbox"
/>
Upvotes: 2
Views: 2157
Reputation: 61
adding layoutdirection "rtl" works:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|center"//or "center_vertical" for center text
android:layoutDirection="rtl"
android:text="hello" />
Upvotes: 0
Reputation: 734
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layoutDirection="rtl"
android:text="Check box One"
android:textSize="12sp"
android:textColor="@android:color/black"
android:textAlignment="textStart"
tools:ignore="MissingPrefix" />
Upvotes: 1
Reputation: 456
Add
android:paddingLeft="0dp"
to avoid the empty space at the checkbox left side. The source link:
How to show android checkbox at right side?
answered by zeusboy.
Upvotes: 0
Reputation: 331
Try the following:
1) Your parent could have a default left padding causing it to leave some space.
2) You can manually set the correct orientation by setting the left margin to 0 with: android:layout_marginLeft
3) You can also set the padding to 0 if margin does not fix it by: android:paddingLeft
4) If none of these fix the problem, use a negative value for margin.
5) You can also try to use a Relative Layout to align the elements
6) Worst case, use absolute positioning
Upvotes: 0
Reputation: 1235
I think your default drawable is occupying the extra area. You can fix this by adding the following line.
android:layout_marginLeft="-40dp"
Upvotes: 3