Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Relative Layout alignParentRight and alignParentEnd

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?

like image 781
Sizdian Avatar asked Apr 11 '15 21:04

Sizdian


People also ask

What is the relative layout explain 5 attributes of relative layout?

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).

What is the difference between ConstraintLayout and RelativeLayout?

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.

What are the relative linear and grid layouts in Android Studio?

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.

How do I align left in relative layout?

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.


2 Answers

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.

like image 175
CommonsWare Avatar answered Sep 20 '22 04:09

CommonsWare


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)║                       ║
╚═══════════════════════════════════╩═══════════════════════╝
like image 26
kenju Avatar answered Sep 19 '22 04:09

kenju