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?
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
Unlike RelativeLayout , ConstraintLayout offers a bias value that is used to position a view in terms of 0% and 100% horizontal and vertical offset relative to the handles (marked with a red circle). These percentages (and fractions) offer seamless positioning of the view across different screen densities and sizes.
Android Layout TypesLinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.
android:layout_alignLeft : With the help of this attribute, we can align the left edge of the new view with the left edge of the specified view ID. android:layout_alignRight : With the help of this attribute, we can align the right edge of the new view with the right edge of the specified view ID.
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.
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)║ ║
╚═══════════════════════════════════╩═══════════════════════╝
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With