I created some CheckBoxes in my android App and added to a LinearLayout programmatically(Dynamically) in code using C#. I want to customize the app for a Right to Left language. I set the Gravity of checkboxes to Right. now I want to change the position of Text of CheckBox to the Left of it dynamically when I'm creating my checkBoxes.how could I do that? I have to use JUST CheckBoxes and I cannot use TextView beside checkBox. Is there any same solution for a RadioButton?! Thanks
Asked
Active
Viewed 3,064 times
1
-
I had the same issue some time ago, I ended up creating a linear layout with a textview and a checkbox. Not sure if that has now changed but it is annoying that this simple thing wasn't present in Android – Moog Feb 05 '14 at 13:19
-
I replaced your [checkbox] and [direction] tags with [monodroid]/[xamarin] tags, since that's the only choices to use C# on Android I am aware off and previous two tags were to generic and checkbox is already part of the Question title. If you use something else than Xamarain.Anroid/monodroid, change accordingly so it gets highlighted to the persons working with these – Tseng Feb 05 '14 at 13:33
-
I too used a TextView in combination with a CheckBox. I subclassed LinearLayout and composed it of these views. I'll see your problem has a direct solution though... – samus Feb 05 '14 at 13:36
-
I just looked at the source code for CheckBox. It's a child of TextView (CheckBox:CompoundButton:Button:TextView). Its looking like you may have to subclass checkbox and override OnDraw to achieve these results, which I don't think is worth the hassle. – samus Feb 05 '14 at 13:46
-
http://androidxref.com/4.0.3_r1/xref/frameworks/base/core/java/android/widget/CheckBox.java – samus Feb 05 '14 at 13:47
-
1Have a look here http://stackoverflow.com/questions/4037795/android-spacing-between-checkbox-and-text – samus Feb 05 '14 at 13:53
-
I'm using minSdkVersion="8" targetSdkVersion="18".and I want a solution for any device in this range of version. because of other methods I wrote before which work with these checkboxes I cannot add a new layout.and I have to just use CheckBox , not textView or anything else. – user3243726 Feb 06 '14 at 07:52
2 Answers
4
For targetSdkVersion=
4.2 or higer, you can set android:layoutDirection attribute to "rtl". See Native RTL support in Android 4.2.
You can set the attribute for the checkBox itself, or let it inherit the layoutDirection from its parent view.
Note that you need <uses-sdk>
element and android:supportsRtl="true"
in the <application>
element of AndroidManifest.xml.
For 2.3.3, the following workaround seems work:
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
android:button="@android:color/transparent".
The value "?android:attr/listChoiceIndicatorMultiple" may be programmatically extracted from android:button
field.

Alex Cohn
- 56,089
- 9
- 113
- 307
-
thank you dear Alex.I'm using minSdkVersion="8" targetSdkVersion="18".and I want a solution for any device in this range of version. because of other methods I wrote before which work with these checkboxes I cannot add a new layout.and I have to just use CheckBox , not textView or anything else. – user3243726 Feb 06 '14 at 07:53
-
Unfortunately, I don't have Froyo devices here, and my AVD does not offer emulator images below API 10. But for 2.3.3, the following workaround seems work: `android:drawableRight="?android:attr/listChoiceIndicatorMultiple"` and `android:button="@android:color/transparent"`. The value "?android:attr/listChoiceIndicatorMultiple" may be programmatically extracted from `android:button` field. – Alex Cohn Feb 06 '14 at 08:55
0
Try setting attribute android:drawablePadding to a negative value.
<CheckBox
...
android:drawablePadding="-100dp"
...
/>

samus
- 6,102
- 6
- 31
- 69
-
@user3243726 "because of other methods I wrote before which work with these checkboxes I cannot add a new layout"... you may be able to insert a TextView to the left of your checkbox dynamically from code. If the View that contains the checkbox isn't already defined explicitly as a class (ie, your inflating it only) then you can try defining a class for it explicitly (subclass the parent most view/viewgroup of the the layout file being instantiated), and then subclass this view and expand it to have another TextView. This would require modifying the parent view name in the layout to the class. – samus Feb 06 '14 at 15:55