Seekbar的拇指点击列表器

我想在seekbar的大拇指上注册一个可点击的事件,以便在用户使用它时打开活动。 可能吗? 我在这里发现了类似的问题Seekbar的拇指点击,但没有找到答案。 我不想移动搜索栏,但想要在用户点击seekbar的时候打开活动。


这会在用户点击拇指时触发。 看到onProgressChanged()的开头希望这有助于。 :)

如果您对其工作原理有任何疑问,请随时发表评论。

mSeekBarSpeed.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    int progress = mSeekBarSpeed.getProgress();

    boolean started = false; //use this variable to see whether the user clicked the right place


    @Override
    public void onProgressChanged(SeekBar seekBar, int progressValue, boolean fromUser) {
        if(!started){ //check to see if user clicks the right place
            //if the user clicks within a specific threshold
            float threshold = (float)seekBar.getMax() / seekBar.getWidth() * seekBar.getThumb().getIntrinsicWidth() / 2;
            if(Math.abs(progressValue - progress) < threshold){
                 if(fromUser){ //checks if user actually clicked it
                     started = true;

                     //IF YOU WANT TO DO SOMETHING RIGHT WHERE THE USER CLICKS IT HERE IS THE PLACE
                 }

            }else{
                seekBar.setProgress(progress); //set to original progress
                onStopTrackingTouch(seekBar); //not really necessary, keep or delete based on your needs
                return; //get out of method
            }
        }

        if(started) {

            progress = progressValue; //update progress variable
            System.out.println("onProgressChanged:" + progress + "/" + seekBar.getMax());

            //DO WHAT YOU NEED TO DO WHEN PROGRESS IS CHANGING

        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        System.out.println("onStartTracking:" + progress + "/" + seekBar.getMax());
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        System.out.println("onStopTracking:" + progress + "/" + seekBar.getMax());
        //DO WHATEVER YOU NEED TO DO WHEN PROGRESS IS DONE CHANGING

        started = false; //remember to set variable to false
    }

});
链接地址: http://www.djcxy.com/p/64337.html

上一篇: Seekbar's thumb on click listner

下一篇: Setting new thumb in SeekBar removes progress background