I\'m trying to create a layout for a ListView, with a checkbox to the right and some text to the left. The checkbox should be aligned all the way to the right and the TextV
And to get the checkbox's box to the right , in check box attributes
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
Just set the switch: Layout Parameters -> Width to "match_parent"
originally it's "wrap_content"
My solution in this case is to use:
<CheckBox
...
android:button="@null"
android:drawableRight="@drawable/my_check"
...
/>
where my_radio could be for example you custom selector! Example of selector could be:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/check_checked" />
<item android:state_checked="false" android:drawable="@drawable/check_unchecked" />
</selector>
You can achieve this by adding layoutDirection to "rtl"
<CheckBox
android:id="@+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right|center"
android:layoutDirection="rtl"
android:text="@string/declare_info_correct" />
Since you are already using a RelativeLayout, make use of it's attributes:
Remove android:gravity
from the children and replace them with android:layout_alignParentLeft="true"
for the TextView and android:layout_alignParentRight="true"
for the CheckBox.
That positions the children relative to the parents borders. You may also want to add android:layout_centerVertical="true"
to each child to center the two vertical within each list item.
For further options and attributes see the documentation.
At the basis of Oibaf it's or MSaudi's solution
android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
to add
android:paddingLeft="0dp"
to avoid the empty space at the checkbox left side in some device. The source link:
How to show android checkbox at right side?
answered by zeusboy.