一旦进度超过 10%,就更改 SeekBar 的 Thumb-Drawable?

发布于 2024-12-29 18:45:17 字数 1243 浏览 2 评论 0原文

一旦进度超过 10%,我就会尝试更改搜索栏的拇指可绘制.. 但事实是.. 一旦进度达到> 10,拇指绘制“消失”..这是一些已知的错误还是只是像这不可能的那样简单?

这是我的代码:

    public class SliderTestActivity extends Activity {
    SeekBar sb;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        sb = (SeekBar)findViewById(R.id.seekBar1);
        sb.setThumb(getResources().getDrawable(R.drawable.fingerprint));
        sb.setProgress(50);
        sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar seekBar) {
                seekBar.setThumb(getResources().getDrawable(R.drawable.egg));

            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                if(progress > 10)
                {
                    sb.setThumb(getResources().getDrawable(R.drawable.egg));
                }

            }
        });
    }
}

提前致谢!

Im trying to change the thumb drawable of a seekbar once the progress is over 10%.. but the thing is..
that once the progress hits > 10, the thumb-drawable "disappears".. is this some know bugs or is it just as simple as this aint supposed to be possible?

Here is my code:

    public class SliderTestActivity extends Activity {
    SeekBar sb;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        sb = (SeekBar)findViewById(R.id.seekBar1);
        sb.setThumb(getResources().getDrawable(R.drawable.fingerprint));
        sb.setProgress(50);
        sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar seekBar) {
                seekBar.setThumb(getResources().getDrawable(R.drawable.egg));

            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                if(progress > 10)
                {
                    sb.setThumb(getResources().getDrawable(R.drawable.egg));
                }

            }
        });
    }
}

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2025-01-05 18:45:17

我在网上发现了这一点:

final Drawable d = getResources().getDrawable(R.drawable.egg);
d.setBounds(new Rect(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()));
slider.setThumb(d);

拇指没有消失,但是更改后它的行为有点奇怪。它不会停在SeekBar的开头和结尾,并且一半是隐藏的。

编辑:
看来 setThumb 还将拇指偏移设置为半宽。通过在设置拇指后将偏移量设置为 0,可以使其表现得像原始拇指一样:

slider.setThumb(d);
slider.setThumbOffset(0);

I found this on the net:

final Drawable d = getResources().getDrawable(R.drawable.egg);
d.setBounds(new Rect(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()));
slider.setThumb(d);

The thumb doesn't disappear, however after the change it behaves a bit strange. It doesn't stop at the begin and end of SeekBar and half of it is hidden.

Edit:
It seams that setThumb also sets thumb offset to half width. By setting offset to 0 after you set the thumb you can make it behave like original thumb:

slider.setThumb(d);
slider.setThumbOffset(0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文