Issue
I am trying not to have a BottomSheet that populates whole screen but to leave some space above when it expanded. Here is my code which onExpand populates whole screen.
bottomSheetBehavior = BottomSheetBehavior.from(bottomLayout);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_DRAGGING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_DRAGGING");
break;
case BottomSheetBehavior.STATE_SETTLING:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_SETTLING");
break;
case BottomSheetBehavior.STATE_EXPANDED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_EXPANDED");
break;
case BottomSheetBehavior.STATE_COLLAPSED:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_COLLAPSED");
break;
case BottomSheetBehavior.STATE_HIDDEN:
Log.i("BottomSheetCallback", "BottomSheetBehavior.STATE_HIDDEN");
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
Log.i("BottomSheetCallback", "slideOffset: " + slideOffset);
boolean drawer = getSupportFragmentManager().getBackStackEntryCount() == 0;
ObjectAnimator.ofFloat(drawerArrow, "progress", drawer ? 0 : 1).start();
}
});
bottomLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.v(TAG, "ONCLickListner");
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
Log.v(TAG,"state expand");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} else {
Log.v(TAG,"state collapse");
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}
});
Can you please address my problem and suggest a way of making bottomsheet not to take whole screen but for leaving some space above when expanded. Thanks
Solution
A simple trick has done it. I was not able to prevent bottom sheet from having full screen for now, so i had a view which is transparent of my required size, and by adding it to the bottomSheetLayout resolved my issue
<View
android:layout_width="match_parent"
android:id="@+id/spaccer"
android:layout_height="28dp"
android:background="@android:color/transparent"
android:alpha="0.6"/>
Answered By - Jay
Answer Checked By - Cary Denson (JavaFixing Admin)