How to close a fragment while pulling up or down?

I use a fragment to show comments and rating, I want to apply an effect, for example, when we pull a fragment up or down, it closes or disappears with animation, for example, a facebook comment layout.

This is my layout. It contains a Recyclerview.

enter image description here

I want that when I drag this layout up or down, it closes the way the facebook comment layout does.

enter image description here

Can you suggest me a way how I can achieve this functionality.

+6
source share
1 answer

One simple trick that may work depending on your use is to implement it using BottomSheetBehaviour .

<strong> Benefits:

  • No external libraries required (other than support)
  • Relatively easy to get started
  • Many examples
  • Easy animation customization based on public void onSlide(@NonNull View bottomSheet, float slideOffset)

You would structure your xml with something like this snippet:

 <android.support.design.widget.CoordinatorLayout > <android.support.design.widget.AppBarLayout > <android.support.design.widget.CollapsingToolbarLayout > <android.support.v7.widget.Toolbar /> </android.support.design.widget.CollapsingToolbarLayout > </android.support.design.widget.AppBarLayout > <include layout="@layout/content_layout" /> <FrameLayout android:layout_width="match_parent" android:layout_height="300dp" android:fitsSystemWindows="true" app:behavior_hideable="false" app:behavior_peekHeight="0dp" app:layout_behavior="@string/bottom_sheet_behavior"> <include layout="@layout/bottom_sheet_content_view" /> </FrameLayout> </android.support.design.widget.CoordinatorLayout> 

Some help to get started:

https://medium.com/@nullthemall/new-bottomsheet-caab21aff19b

https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031

0
source

All Articles