自定义 TranslateAnimation 导致闪烁
我的自定义 TranslateAnimation 确实垂直移动视图。除了开始时有奇怪的短暂闪烁之外,一切都很好。如果视图在意外位置闪烁(比动画应该开始的位置高得多),则似乎只有一个可见帧。
注意:当我调用 super(0,0,0,0) 但没有动画时,不会发生闪烁。
这是我的代码的简短版本:
public class ExTranslateAnimation extends TranslateAnimation implements AnimationListener
{
private View myView;
public ExTranslateAnimation (...)
{
// delta is how much it gets moved
super(0, 0, -delta, 0);
this.setAnimationListener(this);
this.setDuration(duration);
toY = view.getTop() + delta;
myView = view;
}
@Override
public void onAnimationEnd(Animation animation)
{}
@Override
public void onAnimationRepeat(Animation animation)
{}
@Override
public void onAnimationStart(Animation animation)
{
LayoutParams lp = (LayoutParams) myView.getLayoutParams();
lp.leftMargin = toX;
lp.topMargin = toY;
myView.setLayoutParams(lp);
myView.layout(toX, toY, 0, 0);
}
}
My custom TranslateAnimation does move a view vertically. It is fine besides a strange short flickering in the beginning. It seems that it is only one visible frame were the view flashes at a unexpected position (much higher then the animation should start).
Note: That flickering doesn't happen when i call super(0,0,0,0) but then there is no animation.
Here is a short version of my code:
public class ExTranslateAnimation extends TranslateAnimation implements AnimationListener
{
private View myView;
public ExTranslateAnimation (...)
{
// delta is how much it gets moved
super(0, 0, -delta, 0);
this.setAnimationListener(this);
this.setDuration(duration);
toY = view.getTop() + delta;
myView = view;
}
@Override
public void onAnimationEnd(Animation animation)
{}
@Override
public void onAnimationRepeat(Animation animation)
{}
@Override
public void onAnimationStart(Animation animation)
{
LayoutParams lp = (LayoutParams) myView.getLayoutParams();
lp.leftMargin = toX;
lp.topMargin = toY;
myView.setLayoutParams(lp);
myView.layout(toX, toY, 0, 0);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它发生在模拟器还是设备上..因为我曾经遇到过同样的问题,但仅限于设备。在模拟器上它工作正常。
Is it happening on emulator or device.. because i faced the same issue once but it was only in case of device. On emulator it was working fine.