我正在创建一个动画来增加 TextView 的大小。这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5"
android:toXScale="2.5"
android:fromYScale="0.5"
android:toYScale="2.5"
android:duration="4000" />
这是我的 Java 文件:
Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.answeranim);
txtanswer.startAnimation(anim);
我的问题是我的 TextViewer 转到屏幕中心并开始动画。我希望我的 TextViewer 从我已经设置的位置增加他的大小。事实上,我希望动画只是增加 TextViewer 的大小而不改变它的位置。我怎样才能做到这一点?
最佳答案
我认为这可能会给你一些指导,你可能需要稍微调整一下值:
TextView text = (TextView) this.findViewById(R.id.idTesteText);
ScaleAnimation anim = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f,
Animation.RELATIVE_TO_SELF,1.0f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(700);
text.startAnimation(anim);
如果将pivotX和pivotY设置为宽度和高度的一半,如果需要,它将从中心缩放。
您可以在此处查看文档: http://developer.android.com/reference/android/view/animation/ScaleAnimation.html
关于java - 避免android补间动画改变位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15691078/