How to right-align text in an Android TextView or EditText?

sherry picture sherry · Apr 18, 2011 · Viewed 66.9k times · Source

I have an EditText in my application. I want to align the text in it to the right instead of the default left. I tried adding

android:layout_gravity="right"

but this doesn't seem to work. any other suggestions please?

Answer

Randy Sugianto 'Yuku' picture Randy Sugianto 'Yuku' · Apr 18, 2011

You should use android:gravity="right". layout_gravity is for the view (EditText) alignment against the container.