Android BottomSheetBehavior callback method onSlide() gives confusing slideOffset values
android, bottom-sheet, material-design
Solution
I had the same problem as you, I can not say the problem is fixed because the `onSlide` method of the `BottomSheetBehavior.BottomSheetCallback()` is not behaving according to the documentation (values from -1 to 1), but at least I was able to standardize it by setting the peak height to 0, like this:
`bottomSheetBehavior.setPeekHeight(0);`
After adding this line, I saw that `onSlide` method always had positive values (0 - 1).
I'm still trying to understand what is happening in order to find a better solution.
Problem
I am implementing an application where I use a bottom sheet with the behavior defined by `@string/bottom_sheet_behavior`. Additionally I set a `BottomSheetBehavior.BottomSheetCallback()` programmatically because I want to use the onSlide() method to animate a padding. Therefore I really need the slideOffset value to calculate the new padding to set. I read the docs. There they say that the value ranges from -1 to 0 when the state is between hidden and collapsed state. I only can see this behavior when my phone or tablet is in portrait mode and is independent of the android version. However in landscape mode the range goes all from 1 to -1. In detail here is a value history of a bottom sheet going from hidden to expand: ``` D/SLIDE: -0.86160713 D/SLIDE: -0.5714286 D/SLIDE: -0.29910713 D/SLIDE: -0.0625 D/SLIDE: 0.11382114 D/SLIDE: 0.27235773 D/SLIDE: 0.40650406 D/SLIDE: 0.51626015 D/SLIDE: 0.6300813 D/SLIDE: 0.69512194 D/SLIDE: 0.75609756 D/SLIDE: 0.8130081 D/SLIDE: 0.8577236 D/SLIDE: 0.8943089 D/SLIDE: 0.9186992 D/SLIDE: 0.9430894 D/SLIDE: 0.9593496 D/SLIDE: 0.97154474 D/SLIDE: 0.9796748 D/SLIDE: 0.9878049 D/SLIDE: 0.9918699 D/SLIDE: 0.99593496 D/SLIDE: 1.0 ``` I only set the new state of the bottom sheet on a button click. The desired values would begin on -1 and end on 0.0 with more granular steps between. In this history the values increase as well but they go up to +1. Does anybody else had to face the same strange behavior and can give me a hint what I am missing? If any additional code is required I will update my question. Thanks in advance. Peter