I have a layout which works fine. One view is in front, another in the back. I'm using CoordinatorLayour because I'm using a FAB. The front view is a map and the back view is a view showing data when the FAB button is clicked.
For this I've seen those links on SO:
BringToFront doesn't work inside a coordinator layout
Position view below another view in CoordinatorLayout in android
Placing/Overlapping(z-index) a view above another view in android
Based on the answers I did a simple code. But the front view insists to be in front. Is there something I missing?:
final RelativeLayout rev = findViewById(R.id.bg_detail);
final RelativeLayout orange_map = findViewById(R.id.orange_map);
floatingActionButtonEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rev.bringToFront();
rev.getParent().requestLayout();
rev.invalidate();
}
});
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:fitsSystemWindows="true""
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar_base"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/orange_map"
android:background="@android:color/holo_orange_light">
<!--fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" /-->
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bg_detail">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:orientation="vertical"
android:background="@android:color/holo_red_dark"
android:visibility="invisible"
android:id="@+id/dummy"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
...
</RelativeLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/floatingactionbutton_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:src="@drawable/ic_assignment_white_24dp"
app:layout_anchor="@id/dummy"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>