简体   繁体   English

如何避免在为 Android 翻译 animation 时出现闪烁?

[英]How to avoid a blink in Translate animation for Android?

I have a image at position 0,0 initially.我最初在 position 0,0 有一个图像。 When the user clicks a button I animate the image and move it to 0,100 using当用户单击按钮时,我为图像设置动画并将其移动到 0,100 使用

Animation an = new TranslateAnimation(0, 0, 0, listInstanceDetails.DragItemHeight); Animation an = new TranslateAnimation(0, 0, 0, listInstanceDetails.DragItemHeight); an.setFillAfter(true); an.setFillAfter(true);

Since the setFillAfter is true.由于 setFillAfter 为真。 The animation stays at 0,100. animation 保持在 0,100。 Now the user clicks the button again and I want it to come back from 0,100 to 0,0.现在用户再次单击该按钮,我希望它从 0,100 回到 0,0。 So I use the code所以我使用代码

Animation an = new TranslateAnimation(0, 0, 100, 0); Animation an = new TranslateAnimation(0, 0, 100, 0); an.setFillAfter(true); an.setFillAfter(true);

This is working fine.这工作正常。 But when just before the second animation starts from 100,0 It gives a blink at 0,0 and then starts from 100,0 to 0,0.但是,在第二个 animation 从 100,0 开始之前,它会在 0,0 处闪烁,然后从 100,0 开始到 0,0。 This looks very ugly.这看起来非常难看。

Is there a way to avoid this blink.有没有办法避免这种眨眼。 Is there anyone who has played around a lot with Translate animation and done a similar operation.有没有人玩过很多翻译 animation 并做过类似的操作。 Am I doing something wrong.难道我做错了什么。 Please let me know your inputs.请让我知道您的意见。 Thank you for your time and advice.感谢您的时间和建议。

I had used an.setFillBefore(false);我用过 an.setFillBefore(false); in my code.在我的代码中。 I removed it and it started working fine.我删除了它,它开始正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM