如何设置Android BottomSheet扩展高度?

时间:2019-09-19 03:04:11

标签: android material-design bottom-sheet

我正在创建片段按钮表,并希望将高度设置为从屏幕顶部开始大约16dp。 here i是设计的图片,here是我所做的

我的底页片段的oncreate

              if UIApplication.shared.canOpenURL(instagramURL!) {
                    if let url = Auth.auth().currentUser?.photoURL {
                        let imageData = UIImage.jpegData(self.getImage(url: url))
                        let writePath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.igo")
                        do {
                            try imageData.write(to: URL(fileURLWithPath: writePath), options: .atomic)
                        } catch {
//                            print(error)
                        }

                        let fileURL = URL(fileURLWithPath: writePath)
                        self.documentController = UIDocumentInteractionController(url: fileURL)
                        self.documentController.delegate = self
                        self.documentController.uti = "com.instagram.exlusivegram"

                        if UIDevice.current.userInterfaceIdiom == .phone {
                            self.documentController.presentOpenInMenu(from: self.view.bounds, in: self.view, animated: true)
                        }
//                        else {
//                            self.documentController.presentOpenInMenu(from: self.IGBarButton, animated: true)
//                        }
                    } else {
                        let imageData = UIImage.jpegData(UIImage(named: "media")!)
                        let writePath = (NSTemporaryDirectory() as NSString).appendingPathComponent("instagram.igo")
                        do {
                            try imageData.write(to: URL(fileURLWithPath: writePath), options: .atomic)
                        } catch {
//                            print(error)
                        }

                        let fileURL = URL(fileURLWithPath: writePath)
                        self.documentController = UIDocumentInteractionController(url: fileURL)
                        self.documentController.delegate = self
                        self.documentController.uti = "com.instagram.exlusivegram"

                        if UIDevice.current.userInterfaceIdiom == .phone {
                            self.documentController.presentOpenInMenu(from: self.view.bounds, in: self.view, animated: true)
                        }
//                        else {
//                            self.documentController.presentOpenInMenu(from: self.IGBarButton, animated: true)
//                        }
                    }
                }

这是bottom_sheet_product_searh.xml

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val bsView = inflater.inflate(R.layout.bottom_sheet_product_search,container,false)
    /*val behavior = BottomSheetBehavior.from<View>(bsView)
    behavior.peekHeight=500*/
    bsView?.layoutParams?.height=800
    token = SharedPrefManager.getInstance(requireContext()).merchantInfo
    token?.let{idMerchant = ToolKt.getIdMerchant(token!!)}
    searchRecyclerView = bsView.find(R.id.rv_product_search)
    adapter = ProductSearchAdapter{item:ProductModel->itemClicked(item)}
    return bsView
}

如您所见,我设置了偷看高度,但没有任何反应。怎么了?

1 个答案:

答案 0 :(得分:0)

嘿,使用此布局==> androidx.coordinatorlayout.widget.CoordinatorLayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F7F7F8"
    android:fitsSystemWindows="true"
    tools:context=".Buyer.ViewAllProductScreen">



    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#FFF"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

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

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="60dp">


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


    </androidx.coordinatorlayout.widget.CoordinatorLayout>




</androidx.coordinatorlayout.widget.CoordinatorLayout>