I found a neat solution that does not include alpha in it or toggles the button when the box is open or closed (which makes it look like a delay). Programmatically, you can change the border of the end of the button so that it moves from the activity window when changing the offset of the box.
So, first of all, outside the onDrawerSlide method you should get the FAB layout parameters with the following code (depending on the layout of the button in my case, this is FrameLayout ):
final FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fab.getLayoutParams();
Understand that I am doing this based on a simple mathematical linear equation: y = mx + n, and “y” is the field, “m” is the slope (you can change it), “x” is slideOffset and 'n' - default value / original (16dp). Thus, you assign a default marker and tilt to variables as pixels, subject to an abundance of display densities:
int density = (int) Resources.getSystem().getDisplayMetrics().density; final int defaultMargin = 16 * density; final int slope = -100 * density;
Then inside onDrawerSlide do the following:
params.setMarginEnd((int) (slope * slideOffset + defaultMargin)); fab.setLayoutParams(params);
If this does not work for you, try setting the marginEnd button when creating it or set the layout parameter fields as it is (although you will need to check if marginEnd right or left)
params.setMargins(int left, int top, int right, int bottom);
Hope this helps. This is my first answer, so I hope you do not have many complaints about it.