Bra*_*rad 1 android android-animation
我的TranslateAnimation有效,但在动画结束时,它会跳回到原始位置.
LinearLayout rl = (LinearLayout) findViewById(R.id.navPanel);
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, 3.0f
);
animation.setDuration(500);
rl.startAnimation(animation);
Run Code Online (Sandbox Code Playgroud)
如何让它留在最终位置?
旧的(3.0之前的)动画API表现得有些奇怪 - 当它动画时,它只是转换绘制视图的位置,但实际上并不会相对于其父视图移动视图.
为了获取视图留在原地当动画完成后,你可以设置Animation.AnimationListener你的TranslateAnimation.在onAnimationEnd()侦听器的方法中,通过操纵视图将视图移动到其最终的静止位置LayoutParams.
使用animation.setFillAfter(true)您的动画在翻译月底停止它.
http://developer.android.com/reference/android/view/animation/Animation.html#setFillAfter(boolean)
| 归档时间: |
|
| 查看次数: |
6485 次 |
| 最近记录: |