- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试禁用用户在 BottomSheet
上拖动。我想禁用的原因有两件事。 1. 它阻止 ListView
向下滚动,2. 我不希望用户使用拖动来关闭,而是使用 BottomSheetView
上的按钮来关闭。这就是我所做的
bottomSheetBehavior = BottomSheetBehavior.from(bottomAnc);
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
//Log.e("BottomSheet", "Expanded");
} else if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
//Log.e("BottomSheet", "Collapsed");
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
// React to dragging events
bottomSheet.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch (action) {
case MotionEvent.ACTION_DOWN:
return false;
default:
return true;
}
}
});
}
});
底部SheetLayout
<?xml version="1.0" encoding="utf-8"?><FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior"
android:id="@+id/bottomSheet">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:elevation="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Order Items"
android:layout_margin="16dp"
android:textAppearance="@android:style/TextAppearance.Large"/>
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="@drawable/bg_accept"/>
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:background="@drawable/bg_cancel"/>
</LinearLayout>
<ListView
android:id="@+id/item_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:divider="@color/md_divider_black"
android:dividerHeight="1dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
最佳答案
它现在可能不再相关,但我将把它留在这里:
import android.content.Context
import android.util.AttributeSet
import androidx.coordinatorlayout.widget.CoordinatorLayout
import android.view.MotionEvent
import android.view.View
import com.google.android.material.bottomsheet.BottomSheetBehavior
@Suppress("unused")
class LockableBottomSheetBehavior<V : View> : BottomSheetBehavior<V> {
constructor() : super()
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
var swipeEnabled = true
override fun onInterceptTouchEvent(
parent: CoordinatorLayout,
child: V,
event: MotionEvent
): Boolean {
return if (swipeEnabled) {
super.onInterceptTouchEvent(parent, child, event)
} else {
false
}
}
override fun onTouchEvent(parent: CoordinatorLayout, child: V, event: MotionEvent): Boolean {
return if (swipeEnabled) {
super.onTouchEvent(parent, child, event)
} else {
false
}
}
override fun onStartNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: V,
directTargetChild: View,
target: View,
axes: Int,
type: Int
): Boolean {
return if (swipeEnabled) {
super.onStartNestedScroll(
coordinatorLayout,
child,
directTargetChild,
target,
axes,
type
)
} else {
false
}
}
override fun onNestedPreScroll(
coordinatorLayout: CoordinatorLayout,
child: V,
target: View,
dx: Int,
dy: Int,
consumed: IntArray,
type: Int
) {
if (swipeEnabled) {
super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed, type)
}
}
override fun onStopNestedScroll(
coordinatorLayout: CoordinatorLayout,
child: V,
target: View,
type: Int
) {
if (swipeEnabled) {
super.onStopNestedScroll(coordinatorLayout, child, target, type)
}
}
override fun onNestedPreFling(
coordinatorLayout: CoordinatorLayout,
child: V,
target: View,
velocityX: Float,
velocityY: Float
): Boolean {
return if (swipeEnabled) {
super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY)
} else {
false
}
}
}
并在您的 xml 文件中使用它:
app:layout_behavior="com.your.package.LockableBottomSheetBehavior"
它会禁用所有用户操作,当您只想以编程方式控制 BottomSheet 时可以使用它。
关于android - 禁用用户在 BottomSheet 上拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59091203/
我有基于角度 Material 文档的以下代码: 在我的 HTML Abrir BottomSheet 并且,在我的页面 ts 存档中: import { Component, OnInit } f
我想要一些关于如何修改这段代码的帮助,这样我就可以用触摸手势上下滑动这个反应本机底片。我想出了怎么用纽扣来做。在我的Package.json中,我使用了@Gorhom/Bottom-Sheet,“re
我正在为我的一种布局使用 BottomSheet View 。对于一个非常具体的情况,我需要 BottomSheet 的动画持续时间,它通过 setState(...) 方法在布局中滑动。它应该在 4
FAB BottomSheet按下后出现在屏幕上,但是位置不对(见图1),我想做成图2的样子,怎么解决? 我的 Activity : public class FirstscreenActivity
我有一个包含产品详细信息卡片的 BottomSheet。问题是,当我在 Bottom Sheet 处于 展开 状态时单击产品详细信息上的 + 或 - 按钮时,它跳下来。 当它处于关闭状态并且我单击按钮
我正在尝试在我的应用程序中实现 BottomSheet。我正在学习安卓。我已经按照图书馆页面 here 中给出的说明实现了它.我使用了如下的 Java 代码。 findViewById(R.id.bu
我是 Android 的新手 BottomSheet并且我已经成功地尝试了有关如何使用它的示例,但大多数示例仅演示了通过查看点击事件显示/隐藏 BottomSheet。 现在我有以下代码: Botto
我正在使用 bottomsheetlayout 弹出窗口进行社交媒体共享。现在的问题是,它不止一次开放。请帮我解决这个问题。 在我的按钮上单击我调用 asynctask 以下载图像。 @Overrid
我试图不让 BottomSheet 填充整个屏幕,而是在展开时在上方留出一些空间。这是我的 onExpand 填充整个屏幕的代码。 bottomSheetBehavior = BottomSheetB
我有一个 FrameLayout (teaserContainer) 和 BottomSheet (invitesContainer)。 FrameLayout 位于 BottomSheet 之外(和
我一直在尝试设置 Bottomsheet Google 在他们的应用程序(例如 GOOGLE NEWS 等)中使用的方式, This is how Google's Bottomsheet looks
我正在尝试在 Android 中实现类似于下图的摘要 Bottom Sheet 库。有没有什么方法可以将多个 Bottom Sheet 附加到一个 View ,您可以向左/向右滑动以切换并让相邻的 V
目前我正在使用来自 this lib 的底页,我想实现这样的图片动画google map在滑动 bottomsheet 时,我想按照显示的图像一起滑动 imageview,我已经用过这个link fo
我有一个 Bottom Sheet ,里面有一个 NestedScrollView(见下文)。当我按下 FAB 按钮时,我想让这个 NestedScrollView 中的某些部分不可见。但是,当我将一
我正在尝试在布局中使用 BottomSheet。 Root View 是一个 CoordinatorLayout,我想在 Bottom Sheet 的顶部设置 Elevation,所以我将它设置为高值
编辑: package com.walkindeep.teammanagerpreview; import android.content.Context; import android.os.Bun
我遇到 BottomSheetBehaviour 的问题。BottomSheet 在开始时没有扩展到最大高度。但是,它可以滚动到最大高度。但我不想滚动,而是希望 BottomSheet 扩展到其最大高
所以我在 CoordinatorLayout 中使用嵌套子滚动的新支持库行为,我有这样的 View : 我的应用程序有一个要求,这不是新要求,我需要暂时禁用协调器布局的某些元素的滚动。对于这个 b
我已经使用 NestedScrollView 实现了 Bottom Sheet 行为。并且想知道是否可以在外部触摸时隐藏底部 View 。 最佳答案 我终于可以做到了, 使用了以下代码行: @Over
我知道可以像这样设置普通的底板 rememberModalBottomSheetState( initialValue = ModalBottomSheetValue.Hidden, conf
我是一名优秀的程序员,十分优秀!