How do I cancel a “drag” motion on an Android Seekbar?

你离开我真会死。 提交于 2019-12-30 06:44:26

问题


I've been reading through the docs, and I cannot figure out how to cancel a "drag" on a Seekbar once the bar has been completed.

For example, when I drag the bar to the end, I want an event to happen. However, if I keep my finger on the screen and drag my finger past the SeekBar, it keeps firing off that event even after I reset the progress of the Seekbar. How can I prevent this action from happening?

Thanks


回答1:


Try this..it works fine..

mSeekBar.setEnabled(false);



回答2:


seekBarObj.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        int originalProgress;

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            originalProgress = seekBar.getProgress();
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int arg1, boolean fromUser) {
            if(fromUser == true){
                seekBar.setProgress(originalProgress);
            }               
        }
    });


来源:https://stackoverflow.com/questions/2917969/how-do-i-cancel-a-drag-motion-on-an-android-seekbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!