[英]How to avoid blink of View when using animation?
I use translate and rotate animations to position View
inside FrameLayout
in onCreate
event.我使用平移和旋转动画在
onCreate
事件中将View
定位在FrameLayout
内。 I want animations to perform instantly so I set duration for both of them to 0. But when application starts there is a short blink of my View
in top left corner of screen and then it becomes positioned according to animation parameters.我希望动画立即执行,所以我将它们的持续时间设置为 0。但是当应用程序启动时,屏幕左上角的
View
短暂闪烁,然后它会根据动画参数定位。 How can I avoid this blink?我怎样才能避免这种眨眼?
I spent whole day with that problem.我花了一整天的时间来解决这个问题。 fillAfter and fillBefore has nothing to do with that.
fillAfter 和 fillBefore 与此无关。 Try this before animation start:
在动画开始之前试试这个:
view.setVisibility(View.GONE); // view is our View we trying to animate
Then set animation listener for your animation:然后为您的动画设置动画侦听器:
animation.setAnimationListener(new AnimationListener(){
public void onAnimationEnd(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
v.setVisibility(View.VISIBLE);
}
use animation.setFillAfter(true)
or animation.setFillBefore(true)
, depending on your needs.根据您的需要使用
animation.setFillAfter(true)
或animation.setFillBefore(true)
。 This should resolve the blink这应该可以解决眨眼问题
Having a tag inside the parent tag of your animation file will cause this, try it with only one tag and you will see the difference.在动画文件的父标签中有一个标签会导致这种情况,尝试只使用一个标签,你会看到不同之处。 I am working with this right now
我现在正在处理这个
Odaym's answer is the solution for the issue actually. Odaym 的答案实际上是该问题的解决方案。 If you have something like that:
如果你有这样的事情:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<set
android:duration="1000">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
/>
</set>
</set>
Change it into this:改成这样:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true" android:duration="1000">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
/>
</set>
在动画执行代码之后设置可见性但不在“onAnimationEnd”中,也尝试设置持续时间
view.setVisibility(View.VISIBLE); // view is our View we trying to animate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.