如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb?

编程入门 行业动态 更新时间:2024-10-24 10:18:52
本文介绍了如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我正在尝试更改 android 中搜索栏的拇指的可绘制图像.在 onCreate() 方法中,我可以使用以下

Currently I am attempting to change the drawable image of the Thumb of a seekbar in android. In the onCreate() method I am able to effectively change the thumb using the following

mSeekBar.setThumb(myDrawable);

但是,在调用 onCreate 方法后,我尝试使用具有相同方法的不同 drawable 再次更改它,并且拇指消失了.api 描述是设置将在 SeekBar 中进度表末尾绘制的拇指".这是否意味着图像将被绘制出屏幕(如果我用我的搜索栏'fill_parent')?我尝试更改偏移量但无济于事,还有其他人遇到过这个问题吗?或者知道如何在进度变化时更改拇指图像?

However, after the onCreate method is called, I attempt to change it again using a different drawable with the same method and the thumb disappears. The api description is 'Sets the thumb that will be drawn at the end of the progress meter within the SeekBar.' Does this mean that the image will be drawn off screen (if i 'fill_parent' with my seekbar)? I have tried changing the offset with no avail, has anyone else run into this issue? Or know how to change the thumb image while the progress is changing?

我还应该提到,我将我的搜索栏的背景可绘制设置为一个空白的 xml 文件(即没有背景图像).

I also should mention that I am setting my background drawable for the seekbar to a blank xml file (i.e. to not have a background image).

推荐答案

对我有用的一件事是使用 setBounds 方法但是我遇到的问题是在我的应用程序中它重置了拇指的位置可绘制回到行首.我不知道这是否与我的代码的工作方式有关,或者无论它如何实现都会发生.

One thing that has partially worked for me is to use the setBounds method however the problem I have run into is that in my app it resets the position of the thumb drawable back to the beginning of the line. I don't know if this is related to how my code works or if it happens no matter how it is implemented.

Drawable myThumb = getResources().getDrawable(R.drawable.slider_button); myThumb.setBounds(new Rect(0, 0, myThumb.getIntrinsicWidth(),myThumb.getIntrinsicHeight())); skbr.setThumb(myThumb);

更多推荐

如何在“onCreate"方法之后更改可绘制的 Android SeekBar Thumb?

本文发布于:2023-10-08 02:44:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471279.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   如何在   onCreate   Thumb   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!