How to resize RecyclerView when Material BottomSheet is Expanded?

Viewed 240

I have a layout where i have a bottom sheet which could be expanded, then from that bottomsheet i can click some items which then will be added to my RecyclerView, the issue is that when the bottomsheet is expanded i'm unable to see the last added items as the recyclerView goes behind the bottomSheet.

So i would do something like the bottomSheet pushes to top the recyclerView (or that the recyclerView is resized)

The issue is that i was trying to do the resize in onSlide but it doesn't work as expected...

Here is my Layout:

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="2dp"
        app:layout_anchorGravity="top"
        android:layout_marginBottom="60dp"
        app:layout_anchor="@+id/bottomSheet"
        android:padding="2dp"
        android:scrollbars="vertical"
        tools:listitem="@layout/recyclerview_pterm" />

    <include layout="@layout/bottom_sheet_pterm" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

And my BottomSheetBehavior callback:

bottomSheet.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
        if (newState == BottomSheetBehavior.STATE_EXPANDED) {
            mRecyclerViewTOP.scrollToPosition(dummyDataItems.size() - 1);
        }
    }

    @Override
    public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        int padding = bottomSheet.getHeight();
        ViewGroup.LayoutParams params= mRecyclerViewTOP.getLayoutParams();
        params.height = params.height - padding;
        mRecyclerViewTOP.setLayoutParams(params);
    }
});

So how could i make the recyclerView shows ever the last inserted item even when bottomSheet is expanded?

0 Answers
Related