3

I'm working with an EditText, and know that setTextAlignment was not implemented until API 17, but don't see how using setTextAlignment is any easier or better than setGravity. Which should I use for what purposes, or does it not matter?

I find setGravity to be very easy to work with and do what I want, so when should I NOT use this?

Thank you

Tom McFarlin
  • 829
  • 1
  • 9
  • 24

2 Answers2

2

setTextAlignment() is easier to work with in right-to-left locales: You can align by locale-specific text start or text end without needing to know if it's to the left or to the right.

textAlignment alone won't work. For many alignment modes, you need to actually combine it with a gravity.

laalto
  • 150,114
  • 66
  • 286
  • 303
1

setTextAlignment available from API Level 17, You can't use it before 17. But setGravity available from API Level 1. You can use it anywhere.

SetGravity

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself

Gunaseelan
  • 14,415
  • 11
  • 80
  • 128