2014-09-05 88 views
0

我试图设置一个图像视图,显示它的图像超时(水平) 我现在通过扩展ImageView和onDraw工作。从CoveredImageViewImageview揭示动画

@Override 
protected void onDraw(Canvas canvas) { 

    canvas.getClipBounds(mRect); 
    int i = round((float) mRect.width() * mPercent); 
    mRect.right = i + mRect.left; 
    canvas.clipRect(mRect); 

    super.onDraw(canvas); 
    invalidate(); 

} 

mPercent采取的是我要显示的金额,我有它迷上了音乐播放器和搜索条,揭示这样

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
     revealImg.updatePercent((float) progress/(float) seekBar.getMax()); 
    } 
} 

工作一切良好,定时器/歌曲时长时很长,就像< 10分钟,因为它显示得很慢,但如果歌曲像1分钟那样,透露不是一个流畅的动画(图像与设备宽度相同),它像跳跃一样,因为它需要以较小的量显示整个图像时间(希望你明白我的意思)

我知道它为什么做的事情,即时思考,因为onDraw中的clipRect显示每个像素的像素,所以如果歌曲是30秒,而设备是300px宽,则每秒跳过10px,其中10分钟的歌曲只会是。 5px四舍五入到1px(不显着)

林想知道如果有人有更好的方法,使其不波动。我想我也许可以使用ValueAnimator但我不太清楚如何使用它来揭示imageview。

回答

1

使用ValueAnimator找出它!

我刚刚更换

@Override 
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { 
    revealImg.updatePercent((float) progress/(float) seekBar.getMax()); 
} 

@Override 
public void onAnimationUpdate(ValueAnimator animation) { 
    float value = (float) animation.getCurrentPlayTime(); 
    revealImg.updatePercent(value/mixDurationInMilli); 
} 

一切顺利得多,现在:)我只是不明白为什么...:/