如何检测用户何时从 Android 图表中抬起手指

问题描述 投票:0回答:1

我有一个像这样的 XML 布局元素

    <com.highsoft.highcharts.core.HIChartView
        android:id="@+id/chart"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:contentDescription="@{data.chartTypeContentDescription}"
        bind:layout_height="@{data.chartHeight}"
        bind:layout_width="@{data.chartWidth}"
        tools:layout_height="150dp" />

我想要实现的是,如果用户从折线图上抬起他/她的手指(

HIArea()
),那么我想用这个做点什么。据我所知,Highcharts 库并没有真正对此提供原生支持。

我得到的最接近的是使用

setOnTouchListener
但这似乎没有检测到来自图表的任何触摸事件。

    binder.chart.rootView.setOnTouchListener { v, event ->
        Log.d("eqweqeqew", "rootView onTouch: ${event.action}")
        when (event.action) {
            MotionEvent.ACTION_UP -> {
                Log.d("eqweqeqew", "rootView onTouch: MotionEvent.ACTION_DOWN")
            }
        }
        true
    }

    binder.chart.setOnTouchListener { v, event ->
        Log.d("eqweqeqew", "chart onTouch: ${event.action}")
        when (event.action) {
            MotionEvent.ACTION_UP -> {
                Log.d("eqweqeqew", "chart onTouch: MotionEvent.ACTION_DOWN")
            }
        }
        true
    }

两者都没有真正发挥作用。

android kotlin highcharts
1个回答
0
投票

在 Highcharts Android 集成中,底层使用 WebView,因此所有用户交互事件都与 JavaScript 事件紧密相关。我建议使用包装事件和函数。以下是如何在 Highcharts Android 集成中使用函数的有用示例:HiFunction 示例

但是,某些事件(例如

mouseOut
)可能无法以相同的方式工作,因为它们在触摸屏设备上根本没有意义。最好的解决方案是使用与触摸屏设备上的事件重叠的事件(例如,
click
),以确保它们按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.