一旦进度超过 10%,就更改 SeekBar 的 Thumb-Drawable?
一旦进度超过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在网上发现了这一点:
拇指没有消失,但是更改后它的行为有点奇怪。它不会停在SeekBar的开头和结尾,并且一半是隐藏的。
编辑:
看来 setThumb 还将拇指偏移设置为半宽。通过在设置拇指后将偏移量设置为 0,可以使其表现得像原始拇指一样:
I found this on the net:
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: