我想制作一个在其父级左侧对齐的编辑文本,当用户单击它时,编辑文本的宽度将增加到右侧。这是我使用的代码。但是当动画结束时,edittext 宽度达到第一个尺寸。
有人能帮我吗?
有什么解决方案可以在动画中将“fillparent”设置为宽度的最终尺寸吗?
Animation scaleAnimation = new ScaleAnimation(0, -500, 1, 1);
scaleAnimation.setDuration(750);
editText.startAnimation(scaleAnimation);
我在动画开始之前添加了 scaleAnimation.setFillAfter(true);
但我明白了;
750 毫秒后,edittext 将达到其第一个宽度。
最佳答案
这绝对适合您。
Dynamic way of doing this:
ScaleAnimation animate = new ScaleAnimation(1, 2, 1, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
animate.setDuration(700);
animate.setFillAfter(true);
target.startAnimation(animate);
Way of Using XML
scale.xml(放在res/anim文件夹中)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
android:duration="400"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="0%"
android:pivotY="0%"
android:toXScale="2.0"
android:toYScale="1.0" >
</scale>
</set>
Java 代码:
Animation anim = AnimationUtils.loadAnimation(Anims.this, R.anim.scale);
mEdittext.startAnimation(anim);
关于android - Edittext 随动画改变宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21552429/