改变搜索栏的步长值? [英] Changing step values in seekbar?

查看:475
本文介绍了改变搜索栏的步长值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索栏,在移动它,我想要的值更改为0到200我有一个TextView,我在那里显示的值,而移动搜索栏。但我不希望有从该区间(0,1,2,3,4,5 ......)的每一个值,但有10个,20个,30 ...等等。所以,当我移动搜索栏,我想显示10,20,30,40 ....至200有人可以给我一个提示或一个例子,如何做到这一点?

I have a seekbar, while moving it I want to change values from 0 to 200. I have a TextView, where I display those values while moving the seekbar. But I don't want to have every value from that interval(0,1,2,3,4,5...), but to have 10, 20, 30...so on. So when I move the seekbar, I want to display 10,20,30,40....to 200. Can somebody give me a hint or an example how to do this?

推荐答案

尝试下面code

SeekBar seekBar = (SeekBar)layout.findViewById(R.id.seekbar);
seekBar.setProgress(0);
seekBar.incrementProgressBy(10);
seekBar.setMax(200);
TextView seekBarValue = (TextView)layout.findViewById(R.id.seekbarvalue);
seekBarValue.setText(tvRadius.getText().toString().trim());

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        progress = progress / 10;
        progress = progress * 10;
        seekBarValue.setText(String.valueOf(progress));
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
});

setProgress(INT)用于设置搜索栏的初始值

setProgress(int) is used to set starting value of the seek bar

SETMAX(INT)用于设置搜索栏的最大值

setMax(int) is used to set maximum value of seek bar

。如果进度比边界小于或大于你可以设置进度为您定义的边界。

If you want to set boundaries of the seekbar then you can check the progressbar value in the onProgressChanged method. If the progress is less than or greater than the boundary then you can set the progress to the boundary you defined.

这篇关于改变搜索栏的步长值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆