【问题标题】:SeekBar move/drag not workingSeekBar 移动/拖动不起作用
【发布时间】:2016-03-22 12:16:24
【问题描述】:

我有一个(自定义)SeekBar 嵌套在 RelativeLayoutLinearLayout 中,显示为 ListView 的项目。现在,只要我在onProgressChanged 中更新TextView(通过setText),我就会收到ACTION_CANCEL,并且我在SeekBar 上的移动/拖动被取消。如果不更新TextView,则可以正常工作。

知道有什么问题吗?

layout.xml的内容:

<LinearLayout>
    <LinearLayout>
        <RelativeLayout>

            <TextView />

            <SeekBar />
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

自定义SeekBar中的代码:

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
        boolean fromUser) {
    if (fromUser) {
        mProgressTextView.setText(String.valueOf(progress));
    }
}

顺便说一句:这个问题只出现在 Android 6 上。在以前的版本上运行良好。

【问题讨论】:

  • 你能把你的代码放上去吗
  • 您是否使用倍数覆盖您的进度参数并除以 increamentProgressBy 值。就像 progress = progress / increamentProgressBy ;
  • 那种。此 SeekBar 的目的是选择 16 到 28 度之间的温度,步长为 0.5 度。所以 SeekBar 的值/进度在 [0, 12] 中,它映射到温度并显示在 TextView 中。进度本身不受操纵

标签: android listview seekbar


【解决方案1】:

有点晚了,但我也遇到了一个问题,ListView 中的SeekBar 在移动并到达SeekBar 的台阶时收到MotionEvent ACTION_CANCEL 而不释放触摸。

问题是我更改了一些数据并在每次SeekBar 调用onProgressChanged 时调用列表适配器上的notifyDataSetChanged

解决方案:避免在onProgressChanged 中调用notifyDataSetChanged,更改您的数据并在您的SeekBar.OnSeekBarChangeListener 的函数onStopTrackingTouch 中调用notifyDataSetChanged

注意:在我的列表适配器中,我还会在每次调用 onProgressChanged 时更改 TextView 的文本,这不会导致任何问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多