What's the difference between android:textAlignment
and android:gravity
?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
All I can see is that the textAlignment is a member of the View Class and the gravity is the member of TextView class. So for the TextView and its subclasses you can use the gravity while you can use the textAlignment for all Views.
As the TextView and its subclasses need some more text-aligning features, so you can see there are more options in gravity where in textAlignment there are only basic options. Although it is only my guess because I have not found any clear documentation about the difference.
You can see these two links of documentation: textAlignment and gravity.
With API 15,
android:textAlignment
may not have the desired result. The snippet below attempts to centre the firstTextView
object usingandroid:textAlignment="center"
. The second usesandroid:gravity="center_horizontal"
. ThetextAlignment
has no effect whereas the gravity works fine. With API 17+,textAlignment
centres the text as expected.To be certain that your text is aligned correctly with all releases, I'd go with gravity.
Resulting layout in API 15:
Resulting layout in API 17+:
As far as I've seen textAlignment seems to be mostly unused. By it's description, it should do just right or left alignment. Gravity seems to be an improved textAlignment.