我将 TranslateAnimation 应用于具有 FillAfter=true 的 EditText,以保持其在动画末尾的位置。 动画工作正常,但问题是我无法再输入编辑文本。 我认为这是因为动画只影响渲染而不修改实际的 View 坐标。
是否有可能在编辑文本正常工作的情况下保持最终坐标?
谢谢, 丹尼尔
最佳答案
不幸的是,动画仅渲染动画元素的原始像素,而不渲染其“android-intern”位置。最好的解决方案(我能想到的)是使用 AnimationListener 并在动画完成后正确设置动画元素的位置。这是我滑下 searchWrapper 的代码:
public void toggleSearchWrapper() {
AnimationSet set = new AnimationSet(true);
// slideDown Animation
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f
);
animation.setDuration(300);
animation.setFillEnabled(false);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(final Animation anim) {
};
@Override
public void onAnimationRepeat(final Animation anim) {
};
@Override
public void onAnimationEnd(final Animation anim) {
// clear animation to prevent flicker
searchWrapper.clearAnimation();
// set new "real" position of wrapper
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, R.id.branchFinderIncludeHeader);
searchWrapper.setLayoutParams(lp);
}
});
set.addAnimation(animation);
// set and start animation
searchWrapper.startAnimation(animation);
}
关于android - 如何在动画之后将更改应用到 View 位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4397443/