如何设置搜索栏的动画,以便将拇指拖动到搜索栏的最大值,拇指会自动返回初始点。我是一个初学者,所以如果可能的话,请给出详细的答案
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
value = sb.getProgress();
if (value == 50) {
Drawable drawable = getResources().getDrawable(
R.drawable.off);
sb.setThumb(drawable);
}
ValueAnimator anim = ValueAnimator.ofInt(seekBar.getProgress(),0);
anim.setDuration(1000);
anim.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int animProgress = (Integer) animation.getAnimatedValue();
sb.setProgress(animProgress);
}
});
anim.start();
}
});
答案 0 :(得分:2)
我已经得到了我的问题的答案。如果有人需要它,那就是....
SeekBar sb;
ValueAnimator anim;
int value;
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
value = sb.getProgress();
ValueAnimator anim = ValueAnimator.ofInt(value,
sb.getMax());
anim.setDuration(1000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(
ValueAnimator animation) {
value = (Integer) animation
.getAnimatedValue();
sb.setProgress(value);
}
});
anim.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ValueAnimator anim = ValueAnimator.ofInt(0,
sb.getMax());
anim.setDuration(1000);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(
ValueAnimator animation) {
value = (Integer) animation
.getAnimatedValue();
value = 100 - value;
sb.setProgress(value);
}
});
anim.start();
}
}, 1200);
}
});