When the ListView stops interrupting the screen, it overlaps the fab, after which it is no longer possible to click on the fab (until the ListView has reached the fab - fab). All clicks go to list items. The screen shows how the dividers go over the fab.

Emulator view

Gradle

compile 'com.android.support:design:25.3.1' 

XML

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="torin.dmitry.todolist.MainActivity"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="60dp" android:background="@color/colorToolbar" android:elevation="@dimen/normalMargin" /> <FrameLayout android:id="@+id/main_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.FloatingActionButton android:id="@+id/main_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="20dp" android:src="@drawable/ic_cancel" app:elevation="4dp" android:layout_gravity="end|bottom" /> </FrameLayout> </LinearLayout> 

The frame is used for fragments.

 @Override public void setFragment(Fragment f) { getFragmentManager() .beginTransaction() .replace(R.id.main_frame, f) .commit(); 

The problem is only on the emulator (Genymotion, on the native I can not try). It is emulated by the Nexus S API 16,480 x 800.

The physical device on which everything works: Xiaomi API 21 1080 x 1920

  • And where is the listView? or do you programmatically put it on main_frame? - Android Android
  • @ Android Android programmatically on main_frame - torin.dmitry
  • This is the correct behavior, as it is placed on top of your fab. If there is no need to create a listview software, then simply add it to the markup in your frameLayout - Android Android

1 answer 1

Yes, there is such a problem before API 21.

Its essence is that in fact, in your FAB markup is in the container at level 0 and all subsequent elements added overlap it (since the children in the container are drawn in the order of their addition, the latest ones have the maximum z-index) and, accordingly, the clicks do not pass. However, with API 21, FAB is always higher than any view in the same container as it.

You have 3 options:

  1. Set software z-index for FAB:
 ViewCompat.setZ(fab, 42); 
  1. Transform markup so that FAB is always higher in the hierarchy than fragments. For example, by making another FrameLayout inside the current one and adding fragments to it.

  2. Create your own container in which to implement your order of drawing children. Example here: https://stackoverflow.com/a/39161932/3212712

  • Helped the 2nd point. Software to install failed. I tried to prescribe ViewCompat.setZ (fab, 10-42-99) in onCreateView right after linking fab and also every time I change a fragment before and / or after a change - it doesn't work for me - torin.dmitry