3

我正在使用 kotlin 创建底页对话框,它运行良好,但在某些设备中,它从下到上的动画不起作用 -

我的 XML 代码 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. 主要 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 代码

   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) {


        }
    })

我用这个方法来显示底页

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

但在某些设备中,它的动画(从下到上)没有显示。您能否建议我使用动画从下到上的方式进行更改的代码。

4

0 回答 0