- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
标准的 android BottomSheetBehavior 具有树状态:隐藏、折叠和展开。
我想让用户在折叠和展开之间“离开” Bottom Sheet 。现在,使用默认行为,它将捕捉到最接近的折叠或展开。我应该如何禁用此快照功能?
最佳答案
我将展示一种方法来为扩展BottomSheetDialogFragment
的View
实现此类功能。
扩展:
首先覆盖onResume
:
@Override
public void onResume() {
super.onResume();
addGlobaLayoutListener(getView());
}
private void addGlobaLayoutListener(final View view) {
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
setPeekHeight(v.getMeasuredHeight());
v.removeOnLayoutChangeListener(this);
}
});
}
public void setPeekHeight(int peekHeight) {
BottomSheetBehavior behavior = getBottomSheetBehaviour();
if (behavior == null) {
return;
}
behavior.setPeekHeight(peekHeight);
}
上面的代码应该做的只是将 BottomSheet
peekHeight
设置为 View 的高度。这里的关键是函数 getBottomSheetBehaviour()
。实现如下:
private BottomSheetBehavior getBottomSheetBehaviour() {
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) getView().getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
return (BottomSheetBehavior) behavior;
}
return null;
}
这只是检查 View
的父级是否设置了“CoordinatorLayout.LayoutParams”。如果是,设置适当的 BottomSheetBehavior.BottomSheetCallback
(下一部分需要),更重要的是返回 CoordinatorLayout.Behavior
,它应该是 BottomSheetBehavior
。
折叠:
这里 [`BottomSheetBehavior.BottomSheetCallback.onSlide (View bottomSheet, float slideOffset)``]( https://developer.android.com/reference/android/support/design/widget/BottomSheetBehavior.BottomSheetCallback.html#onSlide(android.view.View , float)) 正是我们所需要的。来自[文档]( https://developer.android.com/reference/android/support/design/widget/BottomSheetBehavior.BottomSheetCallback.html#onSlide(android.view.View , float):
Offset increases as this bottom sheet is moving upward. From 0 to 1 the sheet is between collapsed and expanded states and from -1 to 0 it is between hidden and collapsed states.
这意味着,只需检查第二个参数即可进行崩溃检测:
在同一个类中定义 BottomSheetBehavior.BottomSheetCallback
:
private BottomSheetBehavior.BottomSheetCallback mBottomSheetBehaviorCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_HIDDEN) {
dismiss();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (slideOffset < 0) {
dismiss();
}
}
};
关于Android BottomSheetBehavior,如何禁用快照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757240/
Maven – 快照 大型软件应用程序通常由多个模块组成,这是多个团队工作于同一应用程序的不同模块的常见场景。例如一个团队工作负责应用程序的前端应用用户接口工程(app-ui.jar:1.0)),同
我的 ES 快照不起作用或看起来是空的。 首先,我在我的 Ubuntu 服务器上做了这个: 1.创建备份目录 mkdir /home/admin/dumps/elasticsearch 2. 将此目录
您好,我想将折线图保存为预定义尺寸 (x, y) 的图像。有没有简单的方法来做到这一点?我找不到任何合适的 Snapshot 参数。 WritableImage image = lineCha
我将 Genymotion 与 Oracle VirtualBox 一起使用,但是我有 250 GB 的 SSD,并且我遇到了(快照)问题 我在这里搜索并搜索,我找不到任何可能的方法来禁用自动快照,因
我们想使用 Grafana 来显示测量数据。现在,我们的测量设置创建了大量数据并保存在文件中。我们按原样保留文件,并直接使用 Spark(“数据湖”方法)对其进行后处理。 我们现在想要创建一些可视化,
我不知道如何制作节点组的快照。也就是说,我想制作一个覆盖有数字的 PNG 图标图像(例如未读消息)。 我的代码: int totalNumberOfUnreadMessages = 1; ImageV
我们想使用 Grafana 来显示测量数据。现在,我们的测量设置创建了大量数据并保存在文件中。我们按原样保留文件,并直接使用 Spark(“数据湖”方法)对其进行后处理。 我们现在想要创建一些可视化,
这个问题在这里已经有了答案: How do I return the response from an asynchronous call? (41 个回答) 关闭 4 年前。 function i
我试图在运行我的程序时保存所有内容。我想保存每个游戏对象及其脚本和变量。我知道可以序列化所有内容并将其保存为 XML(以及其他方式/格式,如 JSON)。这将需要大量的工作和时间。该程序将来可能会发生
我正在玩 Screeps ( http://screeps.com/ ) 模拟房间模式。我已经测试了一些东西,我不想失去我的进步。 我可以在模拟房间模式下拍摄快照并保存我的房间状态,这样我就不必从头开
我的应用程序的测试人员报告:“最近的应用程序列表中的应用程序缩略图根本没有调整。在我看来,它要么像主屏幕壁纸(tolikdru:可能,只是透明的矩形),要么像应用程序屏幕的绿色背景,但从来没有真正的应
这个问题在这里已经有了答案: JavaFX I want to save Chart-Image completely (1 个回答) 关闭 3 年前。 我正在尝试获取“Java 弹出窗口”的快照。
我正在使用 pymongo 从 MongoDB 中插入和检索数据。这两个操作可以同时执行。问题是我什么时候做 rows = db..find()在pymongo中,每次rows.count()返回不同
如何获取通过 选择的视频文件的快照在视频中的特定时间在后台静默(即没有可见元素、闪烁、声音等)? 最佳答案 主要有四个步骤: 创建 和 元素。 加载src URL.createObjectURL 生
您好,我正在使用 JavaFx WebView 创建 HTML 页面的屏幕截图,它工作正常,但我想知道是否可以在不在图形窗口中启动应用程序的情况下执行此操作!!我的意思是没有比这更轻量级的方法来获取屏
所以我有一个 horizontalscrollview,我想尝试添加一个对齐效果,它基本上使元素居中。到目前为止,我基本上都是用 XML 完成的。 然后我在里面有一个 LinearLayout。
调用 URL http:///gitweb.cgi?p=;a=tree;f=;hb=HEAD将显示 的树从 开始. 调用 URL http:///gitweb.cgi?p=;a=snapshot;
我们知道,Maven 项目第一次构建时,会自动从远程仓库搜索依赖项,并将其下载到本地仓库中。当项目再进行构建时,会直接从本地仓库搜索依赖项并引用,而不会再次向远程仓库获取。这样的设计能够避免项目每次构
这个问题在这里已经有了答案: Freeze screen in chrome debugger / DevTools panel for popover inspection? (9 个回答) 关闭
我正在开发一个向 DVR 和 IP 摄像机请求快照的应用程序。我正在开发的设备只提供 RTSP 请求。然后我实现了必要的 RTSP 方法来开始接收流数据包,然后通过建立的 UDP 连接开始接收。我的疑
我是一名优秀的程序员,十分优秀!