I am trying to ‘float’ a RelativeLayout to the bottom of a Window, and have the following layout:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<com.my.activity.CanvasView
android:id="@+id/canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true" />
<RelativeLayout
android:id="@+id/toolbar_notification"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentBottom="true"
android:gravity="bottom|center_vertical">
<ImageView
android:id="@+id/toolbar_notification_icon"
android:layout_width="40dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:contentDescription="@string/content_desc_save_icon"
android:gravity="center|center_vertical" />
</RelativeLayout>
</merge>
Unfortunately, the toolbar_notification RelativeLayout is not being bottom-aligned. Replacing the merge tag with a FrameLayout tag results in the desired effect, but in the name of efficiency I’d like to remove that if possible.
Anyone seen this issue, or have any suggestions? Is the fact that the merge element is not a ‘parent’ in the true sense resulting in the toolbar_notification element being unable to place itself?
android:gravity="bottom|center_vertical"is referred to children ofRelativeLayoutand not toRelativeLayoutitself.If you want to align
RelativeLayoutto the bottom of the parent (that is aFrameLayout) you have to uselayout_gravityinstead.