展开无需按钮的底部抽屉

huangapple go评论79阅读模式
英文:

Expand Bottom Sheet without a button

问题

我已经创建了一个底部菜单,当屏幕上的按钮被点击时,它会向上滑动。主活动是一个地图 - 带有一个展开底部菜单的按钮。我正在使用 Material 底部菜单库。

主屏幕:
隐藏的底部菜单

展开后的底部菜单(点击时):
展开的菜单

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);
    }
});

这是我想要实现的内容:

与其必须按按钮来展开菜单,我希望用户可以向上滑动以打开底部菜单。

这是我想要的隐藏状态的底部菜单样式。

我尝试使用手势监听器,但似乎不起作用 - 因为主屏幕上有一个地图。它只会移动地图并且不会识别滑动操作。

我对 Android 还不太熟悉,所以真的很感谢您的帮助。

英文:

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. I'm using the Material Bottom sheet library.

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. It only moves the map around and swipe isn't recognized.

I'm fairly new to android so I'd really appreciate the help.

答案1

得分: 0

在您的底部菜单布局XML中,添加以下代码:

app:behavior_peekHeight="20dp" // 根据您的需要更改dp的值
英文:

In your bottom sheet layout xml, add this code

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

huangapple
  • 本文由 发表于 2020年4月10日 06:44:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/61131406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定