首页 > 解决方案 > 如何在 Kotlin 中设置 ViewDragHelper 灵敏度?

问题描述

我在 Kotlin 中使用 SwipeBackActivity 库。该库在滑动活动时使用 ViewDragHelper。这是这个库中的一些代码;

   private final androidx.customview.widget.ViewDragHelper viewDragHelper;

private class ViewDragHelperCallBack extends androidx.customview.widget.ViewDragHelper.Callback {
    private ViewDragHelperCallBack() { /* compiled code */ }

    public boolean tryCaptureView(android.view.View child, int pointerId) { /* compiled code */ }

    public int getViewVerticalDragRange(android.view.View child) { /* compiled code */ }

    public int getViewHorizontalDragRange(android.view.View child) { /* compiled code */ }

    public int clampViewPositionVertical(android.view.View child, int top, int dy) { /* compiled code */ }

    public int clampViewPositionHorizontal(android.view.View child, int left, int dx) { /* compiled code */ }

    public void onViewDragStateChanged(int state) { /* compiled code */ }

    public void onViewPositionChanged(android.view.View changedView, int left, int top, int dx, int dy) { /* compiled code */ }

    public void onViewReleased(android.view.View releasedChild, float xvel, float yvel) { /* compiled code */ }
}

我想设置拖动灵敏度。有人就来自 github 的问题写了这段代码。

  viewDragHelper = ViewDragHelper.create(this, 0.1f, new ViewDragHelperCallBack());

但我找不到如何使用此代码。如何在 Kotlin 中定义 viewDragHelper?如何在我的项目中设置 viewDragHelper?

标签: androidkotlin

解决方案


推荐阅读