gpt4 book ai didi

java - TranslateAnimation 未按预期工作

转载 作者:太空狗 更新时间:2023-10-29 14:28:54 25 4
gpt4 key购买 nike

我想使用 TranslateAnimation 移动一些线性布局。我有两个问题。我的基础 SDK 是 Android 2.2。

  1. 即使动画结束,线性布局中的可触摸区域也没有移动。
  2. 动画结束后屏幕闪烁了几帧。

起初,我并没有使用AnimationListener和LinearLayout.layout()。当我使用以下代码完成动画时, View 的位置确实发生了变化。但是在动画过程中,可触摸区域似乎没有随 View 移动。结果,当我尝试在动画后单击 View 上的任何按钮时,什么也没有发生。如果我单击按钮的原始区域(动画发生之前的原始区域),则会触发 on_click_listener。

然后我删除了这行代码,

tmpAnimation.setFillAfter(true);

并尝试了 AnimationListenerLinearLayout.layout()。它确实帮助解决了第一个问题。

但是问题2来了。动画结束后,我的一些线性布局会闪烁几帧,然后恢复原状。

我试过 midLinearlayout.requestLayout(),它不起作用。我试过实现 Animation.AnimationListener 并像有人说的那样覆盖 onAnimationEnd,但它也不起作用。

TranslateAnimation tmpAnimation = new TranslateAnimation(midLinearlayout.getLeft(),midLinearlayout.getLeft(),midLinearlayout.getTop(),midLinearlayout.getTop()+100);

//tmpAnimation.setFillAfter(true);

tmpAnimation.setDuration(2000);
tmpAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}

@Override
public void onAnimationEnd(Animation animation) {
Log.v("onflingTest","top="+midLinearlayout.getTop()+" left="+midLinearlayout.getLeft()+" right" + midLinearlayout.getRight());
midLinearlayout.layout(midLinearlayout.getLeft(), midLinearlayout.getTop()+100, midLinearlayout.getLeft() + midLinearlayout.getMeasuredWidth(), midLinearlayout.getTop()+ 100 + midLinearlayout.getMeasuredHeight());
}

@Override
public void onAnimationRepeat(Animation animation) {
//To change body of implemented methods use File | Settings | File Templates.
}
});

我已经通过下面的代码解决了这个问题:

linearlayout.clearAnimation();

查看链接: EditText stucks after animation and alive back on scrolling......?

最佳答案

我在帖子 View.GONE in animation complete 的帮助下解决了这个问题

问题是布局 B 完成动画后,我没有将 View 状态设置为 View.GONE。添加 View.GONE 恢复了控件。

关于java - TranslateAnimation 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8848562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com