3

I am using kotlin for create bottomsheet dialog it is working perfect but in some devices its animation from bottom to top not working -

My XML code 1. content_bottom_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/bottomSheetLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bottom_sheet_rounded"
            app:behavior_hideable="true"
            app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
            android:layout_alignParentBottom="true"
            app:behavior_peekHeight="@dimen/_340sdp"
 >

  ////
  ///

</RelativeLayout>
  1. Main XML ( main.xml )

       <?xml version="1.0" encoding="utf-8"?>
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:id="@+id/bottomSheetLayout"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="@drawable/bottom_sheet_rounded"
            >
    
    
          ///
          ///
          <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="30dp">
    
            <include
                    android:id="@+id/bottomSheetDialog"
                    layout="@layout/content_bottom_sheet"></include>
          </android.support.design.widget.CoordinatorLayout>
    
    
       </RelativeLayout>
    

Kotlin Code for open the bottomsheet

   bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetDialog)

    (bottomSheetBehavior as BottomSheetBehavior<View>?)?.state = BottomSheetBehavior.STATE_HIDDEN

    (bottomSheetBehavior as BottomSheetBehavior<View>?)?.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
        override fun onStateChanged(bottomSheet: View, newState: Int) {
            when (newState) {

                BottomSheetBehavior.STATE_EXPANDED -> {

                }

                BottomSheetBehavior.STATE_COLLAPSED -> {

                }

                BottomSheetBehavior.STATE_HALF_EXPANDED -> {

                }

                BottomSheetBehavior.STATE_HIDDEN -> {


                }

                BottomSheetBehavior.STATE_HALF_EXPANDED->{


                }
            }
        }
        override fun onSlide(bottomSheet: View, slideOffset: Float) {


        }
    })

I use this method to show the bottomsheet

    if(bottomSheetBehavior?.state != BottomSheetBehavior.STATE_STATE_COLLAPSED){
        bottomSheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
    }

But in some devices its animation ( coming from bottom to top ) not showing. Can you please suggest me the code to make changes in the way it comes from bottom to top with animation.

0 Answers0