How to add OvershootInterpolator to Android (java) Bottom Sheet Dialog animation without causing empty gap?

117 Views Asked by At

It is easy to set slide animation to Android Bottom sheets in java. This approach uses android window and slide everything up. But the problem of this approach is appear when we want to add OvershootInterpolator to its animation. In such case, a gap appear between the bottom sheet bottom edge and screen bottom edge with duration of OvershootInterpolator duration. (see Below)

enter image description here

I want the overshoot animation to be affected without windows jump.

enter image description here

My try: I tried to animate my layout using objectAnimator or with similar tool. But this approch has some problems. The container windows cuts everything out to its outline. and when bottomSheet layout reaches to its max height and tries to apply OvershootInterpolator (go a little further and back to current position) the bottomsheet head become invisible until it back to its normal position.

Here is the my test Layout and code.

<!-- bottom_sheet_dialog.xml -->

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rootLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:orientation="vertical"
    android:background="@color/#487948"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">


</LinearLayout>
<!-- code -->

BottomSheetDialog sheetDialog = new BottomSheetDialog(this, R.style.TransparentBackgroundStyle);
        sheetDialog.setContentView(R.layout.bottom_sheet_dialog);
        Objects.requireNonNull(sheetDialog.getWindow()).setWindowAnimations(R.style.Slid);
        sheetDialog.getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
        sheetDialog.show();

I tried to work with BottomSheetBehavior but I couldn't animate (show animation) bottomsheet. Instead I followed this post and successfully animated it during user interaction and not in show or dismiss process.

Can one use BottomSheetBehavior to animate bottomsheet during show or dismiss process?

0

There are 0 best solutions below