【问题标题】:How to fix a lag when scrolling over a line chart that has already been drawn in scichart android滚动已在 scichart android 中绘制的折线图时如何修复延迟
【发布时间】:2020-05-10 10:38:30
【问题描述】:

我有一个已经绘制并与声音同步的折线图。 当我们播放声音时,图表开始水平滚动。 但问题是滚动图表时滞后。 有没有办法解决这个问题?

private Runnable mRunnable = new Runnable() {
@Override
public void run() {
    forceRunInPauseMode = false;

    getActivity().runOnUiThread(() -> {
        currentTime = (int) exoPlayer.getCurrentPosition();
        binding.tvCurrentDuration.setText(MiliToTimeConverter.milliToTime(currentTime));
    });

    int currentRange = currentTime * 2;


    if (!isDraw) {
        DoubleValues xValues = new DoubleValues(Arrays.copyOfRange(xDoubleArray, 0, xDoubleArray.length - 1));
        DoubleValues yValues = new DoubleValues(Arrays.copyOfRange(yDoubleArray, 0, yDoubleArray.length - 1));
        DoubleSeries doubleSeries = new DoubleSeries(xValues, yValues);
        lineData.append(doubleSeries.getxValues(), doubleSeries.getyValues());
        isDraw = true;
    }
    xVisibleRange.setMinMax(currentRange - visibleInterval / 2, currentRange + visibleInterval / 2);
}};


private void updateChart() {
schedule = scheduledExecutorService.scheduleWithFixedDelay(() -> {
    if (!isPlaying && !forceRunInPauseMode)
        return;
    UpdateSuspender.using(binding.sciChart, mRunnable);
}, 0, TIME_INTERVAL, TimeUnit.MILLISECONDS);}


private void pause() {
exoPlayer.setPlayWhenReady(false);
binding.ivPlay.setImageResource(R.drawable.ic_play);
if (schedule != null)
    schedule.cancel(false);}

【问题讨论】:

  • 您是否尝试使用 Android Studio 分析器分析您的应用程序?它显示了什么?

标签: android scroll scichart


【解决方案1】:

我看到的唯一可以改进的地方是创建双数组,在 run() 中使用后是 GC。如果数组的大小很大或/并且它被多次重新创建,这可能会导致性能显着下降。

我建议在 run() 调用之外缓存 DoubleValues 并重用它们。

 private Runnable mRunnable = new Runnable() {
    private final DoubleValues xValues = new DoubleValues();
    private final DoubleValues yValues = new DoubleValues();
    @Override
    public void run() {
        forceRunInPauseMode = false;

        getActivity().runOnUiThread(() -> {
            currentTime = (int) exoPlayer.getCurrentPosition();
            binding.tvCurrentDuration.setText(MiliToTimeConverter.milliToTime(currentTime));
        });

        int currentRange = currentTime * 2;


        if (!isDraw) {
            xValues.setSize(xDoubleArray.length);
            yValues.setSize(yDoubleArray.length);

            System.arraycopy(xDoubleArray, 0, xValues.getItemsArray(), 0, xDoubleArray.length);
            System.arraycopy(yDoubleArray, 0, yValues.getItemsArray(), 0, yDoubleArray.length);

            lineData.append(xValues, yValues);
            isDraw = true;
        }
        xVisibleRange.setMinMax(currentRange - visibleInterval / 2, currentRange + visibleInterval / 2);
    }};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 2016-02-27
    相关资源
    最近更新 更多