如何在 Android 中为视图设置动画并使其保持在新的位置/大小? [英] How to animate a view in Android and have it stay in the new position/size?
问题描述
我目前在我的 Android 应用中有一个视图,并且该视图正在播放帧动画.我想为视图设置动画以将其大小增加到 150%.当我对其应用缩放动画并完成缩放动画时,我希望查看器在 Activity 的其余生命周期中保持该新大小.不幸的是,当放大动画完成时,视图会恢复到原始大小.我怎样才能让它保持新的动画转换?
I currently have a view in my Android app and the view is playing a frame animation. I want to animate the view to increase its size to 150%. When I apply a scale animation to it, and the scale animation is completed, I want the viewer to stay at that new size for the rest of the activity's life cycle. Unfortunately right now when the scale-up animation is complete, the view snaps back to the original size. How can I get it to keep the new animated transformation?
我正在使用
myView.startAnimation(AnimationUtils.loadAnimation(mContext,R.anim.scaleUp150));
谢谢!
推荐答案
确保将以下属性添加到动画 xml 中的根元素:
Make sure you add below attributes to the root element in your animation xml:
android:fillAfter="true"
android:fillEnabled="true"
这篇关于如何在 Android 中为视图设置动画并使其保持在新的位置/大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!