Unfotunately die Animation macht nur die rohen Pixel des animiertes Element, aber nicht seine "android-intern" Position. Die beste Lösung (die ich mir vorstellen kann) besteht darin, einen AnimationsListener zu verwenden und die Position des animierten Elements nach Beendigung der Animation korrekt einzustellen. Hier ist mein Code zum slideDown ein 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);
}