如何实现将View向上平移自身高度一半的距离?
TranslateAnimation translate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f);
mView.startAnimation(translate);
问题:当动画结束后,View会跳回到原始位置。
改进:
AnimationSet set = new AnimationSet(true);
TranslateAnimation translate = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.5f);
set.addAnimation(translate);
set.setFillAfter(true);
mView.startAnimation(set);
setFillAfter文档说明:
If fillAfter is true, the transformation that this animation performed
will persist when it is finished. Defaults to false if not set.
设为true之后,界面会停留在动画播放完时的界面。
问题:动画结束后界面显示正确,但是View上各控件的实际位置和看上去的位