如何在初始估算值和反向重复之间延迟
我有一个两行TextView,我试图执行以下操作:
- 当数据到达时,淡出第二行仅
- 更改第二行中显示的数据
- 淡出的数据淡入
我当前正在使用的 第二行。以下代码来实现这一目标:
ValueAnimator alphaAnim = ValueAnimator.ofInt(255,0).setDuration(1000);
alphaAnim.setRepeatMode(ValueAnimator.REVERSE);
alphaAnim.setRepeatCount(1);
alphaAnim.setStartDelay(500);
alphaAnim.addUpdateListener(valueAnimator -> {
int alpha = (int) valueAnimator.getAnimatedValue();
int newColor = binding.ForegroundSpanText.getCurrentTextColor() & 0x00ffff | (alpha <<24);
SpannableString tempStringHolder = binding.getAnimString();
if(fadingSpan !=null){
tempStringHolder.removeSpan(fadingSpan);
}
fadingSpan = new ForegroundColorSpan(newColor);
tempStringHolder.setSpan(fadingSpan, tempStringHolder.toString().indexOf("\n"), tempStringHolder.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
if(Integer.toHexString(newColor).equals("1000000") && !tempStringHolder.toString().equals("This is my test text with lots of text\n and this is the new text that will animate in!!")){
animStringHolder = new SpannableString("This is my test text with lots of text\n and this is the new text that will animate in!!");
binding.setAnimString(animStringHolder);
binding.executePendingBindings();
}else{
binding.setAnimString(tempStringHolder);
}
});
我当前遇到的问题是:
- 初始文本和我更改的文本之间的更改仍然可见逆转。我意识到这可以使用第二个动画师来完成,但希望有人可能对没有这样做有所了解。
- 另外,如果有人有更好的方法来设置数据/检查第一个动画仪的终点是否达到了很棒,我试图覆盖onAnimationEnd()函数,但是当整个动画结束时发生,这意味着在反向重复。
I have a two line textview where I am attempting to do the following:
- when data arrives, fade out the second line only
- change the data presented in the second line
- fade the second line back in
I am currently using the following code to accomplish this:
ValueAnimator alphaAnim = ValueAnimator.ofInt(255,0).setDuration(1000);
alphaAnim.setRepeatMode(ValueAnimator.REVERSE);
alphaAnim.setRepeatCount(1);
alphaAnim.setStartDelay(500);
alphaAnim.addUpdateListener(valueAnimator -> {
int alpha = (int) valueAnimator.getAnimatedValue();
int newColor = binding.ForegroundSpanText.getCurrentTextColor() & 0x00ffff | (alpha <<24);
SpannableString tempStringHolder = binding.getAnimString();
if(fadingSpan !=null){
tempStringHolder.removeSpan(fadingSpan);
}
fadingSpan = new ForegroundColorSpan(newColor);
tempStringHolder.setSpan(fadingSpan, tempStringHolder.toString().indexOf("\n"), tempStringHolder.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
if(Integer.toHexString(newColor).equals("1000000") && !tempStringHolder.toString().equals("This is my test text with lots of text\n and this is the new text that will animate in!!")){
animStringHolder = new SpannableString("This is my test text with lots of text\n and this is the new text that will animate in!!");
binding.setAnimString(animStringHolder);
binding.executePendingBindings();
}else{
binding.setAnimString(tempStringHolder);
}
});
The issues I am currently running into are:
- The change between the initial text and the text I change to is still visible because the reverse animation happens immediately, so I am looking for a way to add a delay between the reversal. I realize that this could be done with a second animator but was hoping someone might have some idea of how to accomplish this without.
- Also if anyone has a better way to set the data/check if the end point of the first animator has been reached that would be awesome, I tried to override the onAnimationEnd() function but that occurs when the entire animation finishes, meaning after the reverse repeat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
In further research I found onAnimationRepeat() which is part of AnimationListenerAdapter 。因此,将其作为我最初发布的一部分的代码将是:
In further research I found onAnimationRepeat() which is part of AnimationListenerAdapter. So the code to make this a part of what I posted originally would look like: