英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论