Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close a fragment on pulling up or down?

I am using a fragment to show the comments and rating, I want to put a effect like when we pull the fragment up or down it get closed or disappear with animation, like the layout of facebook comment.

This is my layout, It contains a Recyclerview.

enter image description here

I want that when I pull this layout up or down, it closes like this as facebook comment layout does.

enter image description here

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

like image 885
Rahul Avatar asked Nov 10 '22 04:11

Rahul


1 Answers

One simple trick, that might work depending on your usecase, is to implement it using BottomSheetBehaviour.

Advantages:

  • No external libraries required (other than support-design)
  • Relatively easy to get started
  • Plenty of examples
  • Easy to tweak animations, based on the public void onSlide(@NonNull View bottomSheet, float slideOffset)

You would structure you xml 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

like image 196
Entreco Avatar answered Nov 14 '22 21:11

Entreco