如何在Android中为视图设置动画并使其保持新的位置/大小? [英] How to animate a view in Android and have it stay in the new position/size?

查看:421
本文介绍了如何在Android中为视图设置动画并使其保持新的位置/大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在我的Android应用中有一个视图,该视图正在播放帧动画。我想给视图添加动画以将其大小增加到150%。当我将比例动画应用于比例动画并且比例动画完成后,我希望观众在活动的整个生命周期中都保持新的尺寸。不幸的是,现在放大动画完成后,视图会恢复为原始大小。如何获得新的动画转换呢?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆