Android Relative Layout alignParentRight and alignParentEnd

家住魔仙堡 提交于 2019-12-03 16:10:35

I figured the end of a parent was always its right

Only for left-to-right (LTR) languages. For right-to-left (RTL) languages (e.g., Hebrew, Arabic), end is left and start is right. If you use end and start attributes, your layout will mirror when it is run on a device set to an RTL locale. If you use left and right, it will not mirror.

itiskj

Let me add 1 more point beside @CommonsWare's answer. Please be aware that alignStart, alignEnd and alignParentEnd, alignParentStart were added in API Level 17, so that you cannot use those attributes before 17.

https://developer.android.com/reference/android/R.attr.html#layout_alignParentEnd

╔═══════════════════════════════════╦═══════════════════════╗
║ API Level 1                       ║ API Level 17          ║
╠═══════════════════════════════════╬═══════════════════════╣
║ alignBaseLine                     ║ align(Start/End)      ║
║ alignWithParentIfMissing          ║ alignParent(Start/End)║
║ align(Top/Bottom/Left/Right)      ║                       ║
║ alignParent(Top/Bottom/Left/Right)║                       ║
╚═══════════════════════════════════╩═══════════════════════╝

alignParentEnd and alignParentStart are used in RTL (right-to-left) layouts in countries where this is a historical norm. In this case "end" actually becomes "left" instead of "right". If you provide all your views with these attributes, your layout will look like horizontally flipped in RTL layouts, which is more convenient for users in these countries.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!