简体   繁体   English

展开没有按钮的底部工作表

[英]Expand Bottom Sheet without a button

I've created a bottom sheet that swipes up when a button on the screen is clicked.我创建了一个底部工作表,当单击屏幕上的按钮时会向上滑动。 The main activity is a map - with a button that expands the bottom sheet.主要活动是 map - 带有一个展开底部工作表的按钮。 I'm using the Material Bottom sheet library.我正在使用 Material Bottom 表库。

Main Screen: Hidden Bottom Sheet主屏幕:隐藏的底页

Expanded Bottom Sheet on click: Expanded Sheet单击时展开的底部工作表:展开的工作表

       mBottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);
        mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

   button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HALF_EXPANDED);

            }
        });

Here's want I want to implement:这是我想要实现的:

Instead of having to press a button to expand the sheet, I want the user to be able to swipe up and open the bottom sheet.我希望用户能够向上滑动并打开底部工作表,而不是必须按下按钮来展开工作表。

This is what I want the bottom sheet to look like hidden.这就是我希望底部工作表看起来隐藏的内容。

I've tried using Gesture Listener but that doesn't seem to work - since the main screen has a map.我试过使用手势监听器,但这似乎不起作用——因为主屏幕有一个 map。 It only moves the map around and swipe isn't recognized.它只会移动 map 并且无法识别滑动。

I'm fairly new to android so I'd really appreciate the help.我对 android 相当陌生,所以我非常感谢您的帮助。

In your bottom sheet layout xml, add this code在您的底部工作表布局 xml 中,添加此代码

app:behavior_peekHeight="20dp" // change the dp as your need

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM