Android Relative Layout alignParentRight and alignParentEnd

爷,独闯天下 提交于 2019-12-21 05:06:11

问题


I'm trying to figure out the difference between the layout params for relative layout, specifically alignParentRight and alignParentEnd (also alignParentLeft and alignParentStart). Reading the reference doesn't help much, I figured the end of a parent was always its right. Is there any difference to this? Is one depreciated now?


回答1:


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.




回答2:


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)║                       ║
╚═══════════════════════════════════╩═══════════════════════╝



回答3:


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.



来源:https://stackoverflow.com/questions/29583307/android-relative-layout-alignparentright-and-alignparentend

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