Relative Layout alignParentLeft vs alignParentStart

Andrew S picture Andrew S · Jan 14, 2015 · Viewed 16.6k times · Source

So I am comfortable with using relative layouts, but whilst getting used to Android Studio I noticed that in my relative layout child views it generated both of the following.

android:layout_alignParentLeft="true"
android:layout_alignParentStart="true

I have checked out the Android docs here, but cannot see a distinction between the two. Certainly swapping one for another in the Android Studio shows no visible difference. Is there one?

Answer

samgak picture samgak · Jan 14, 2015

It depends on the layout direction. The layout direction can be either left-to-right (start = left, end = right), or right-to-left (vice versa).

By default, the layout direction is based on the locale (left-to-right for languages like English, right-to-left for languages like Arabic), but you can override it with the layoutDirection XML attribute or setLayoutDirection function. e.g.:

android:layoutDirection="ltr"   

^ will make alignParentStart equivalent to alignParentLeft on all devices.

android:layoutDirection="rtl"   

^ will make alignParentStart equivalent to alignParentRight on all devices. You can also set to "locale" to use the locale or "inherit" to inherit the layout direction from the parent view.

You need to add android:supportsRtl="true" to your AndroidManifest.xml to support right-to-left layouts.

also related: android:textDirection