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?
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
android:layout_alignParentStart="true"
Aligns the start edge of this view to the start edge of its parent. This is the left edge for LTR (left to right) locales and the right one on RTL (right to left) locale languages like Arabic, Hebrew, Persian etc.
The reason Android Studio also adds
android:layout_alignParentLeft="true"
to your views is to support older platforms that came before 4.2.x Jelly Bean
. The Start/End attributes like layout_alignParentStart
are only available from API 17 onwards. The newer platforms fallback to Left/Right attributes only if the corresponding Start/End attributes are not found.
In case, your application supports legacy platforms using android:minSdkVersion
below level 17
you must always provide Left/Right attributes for your views. Otherwise the project won't compile with an error message like
To support older versions than API 17 (project specifies 7) you should also add android:layout_alignParentLeft="true"
Also note that your Android application needs to declare its support for RTL locales within your AndroidManifest.xml
as well.
<application
...
android:supportsRtl="true"
/>
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