Android tricks – How to make the text of a RadioButton appear on it’s left side?

Let’s start 2017 with a quick and useful ‘How to’ article!

Have you ever tried to make the text of a RadioButton appear on it’s left side? It’s tricky! You can check to source code down below:

Code description:

By default, for the usual left-to-right layout, the text appears on the right side of the RadioButton. As you can see from the snipped above, we actually use a particular property to change the direction of the current view:
android:layoutDirection="rtl"

In this way, we kind of try to trick the OS. How? By telling Android that this view is supposed to be read / used by a person who reads from right to left. That’s not true, but it works for us!

After that little lie, you can align and change the gravity of the text according to your particular case.

And as Irshu said in the Stackoverflow discussion from the References section – don’t forget to set the supportsRtl property to true of your <application> tag in the Manifest file.

There are some other methods / tricks, which can be used, but there are some side effects as well. You can check the discussion mentioned above, if you want to make use of some of the methods.

References:

http://stackoverflow.com/questions/18914792/how-to-put-the-text-on-the-left-of-a-radio-button-in-android

Feel free to share, comment & give your opinion on the topic!

And only if you really REALLY liked the article, you can buy me a cup of coffee! Otherwise, don’t do it! Donate $1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s