Issue
My layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp">
<TextView
android:id="@+id/crime_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Crime Title" />
<TextView
android:id="@+id/crime_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/crime_title"
android:text="Crime Date" />
<Button
android:id="@+id/crime_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/crime_title" />
</RelativeLayout>
Output:
If i replace android:layout_alignRight="@id/crime_title"
with android:layout_alignEnd="@id/crime_title"
, i get the following output:
The documentation says about alignEnd :Makes the end edge of this view match the end edge of the given anchor view ID
, whereas about alignRight: Makes the right edge of this view match the right edge of the given anchor view ID
Question: Isn't "a right edge" the same as "an end edge" ? And what does that blue circle, that has appeared, mean ? What is the difference between these two attributes ?
Solution
When using android:layout_alignRight
you get a compiler warning saying
Consider replacing android:layout_alignRight with android:layout_alignEnd="@id/crime_title" to better support right-to-left layouts
If you dont use any right-to-left layouts you won't see any difference between android:layout_alignRight
and android:layout_alignEnd
. They behave same.
You can see the difference in preview while editing your layout file by enabling "Preview Right to Left".
When using android:layout_alignRight
your button will stay always on the right even in right to left layouts:
When using android:layout_alignEnd
your button will be automatically positioned to ensure matching the end edge of the given anchor view ID. This is also what that blue circle means:
Answered By - memres
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.