【发布时间】:2011-10-28 20:42:39
【问题描述】:
我将 TranslateAnimation 应用于具有 FillAfter=true 的 EditText,以保持其在动画结束时的位置。 动画工作正常,但问题是我不能再进入编辑文本了。 我认为这是因为动画只影响渲染而不修改实际视图坐标。
是否有可能在编辑文本正常工作的情况下保持最终坐标?
谢谢, 丹尼尔
【问题讨论】:
标签: android animation coordinates android-edittext
我将 TranslateAnimation 应用于具有 FillAfter=true 的 EditText,以保持其在动画结束时的位置。 动画工作正常,但问题是我不能再进入编辑文本了。 我认为这是因为动画只影响渲染而不修改实际视图坐标。
是否有可能在编辑文本正常工作的情况下保持最终坐标?
谢谢, 丹尼尔
【问题讨论】:
标签: android animation coordinates android-edittext
不幸的是,动画只渲染动画元素的原始像素,而不是它的“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);
}
【讨论】: