EDITTEXT变化幅度动画 [英] Edittext change width with animation

查看:689
本文介绍了EDITTEXT变化幅度动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个EditText它对准在其父母的左,当用户点击它,EditText上的width'll提高到右侧。这里是code,我用。但是,当动画结束后,宽度的EditText来第一大小。照片任何一个可以帮助我吗?
并没有任何解决方案设置fillparent在动画宽度的最终大小?

 动画scaleAnimation =新ScaleAnimation(0,-500,1,1);
scaleAnimation.setDuration(750);
editText.startAnimation(scaleAnimation);
 

我添加 scaleAnimation.setFillAfter(真); 前动画开始,但我得到这一点;

750毫秒后,的EditText是要它的第一宽度。

解决方案

这绝对会为你工作。

  

这样的动态方式:

  ScaleAnimation动画=新ScaleAnimation(1,2,1,1,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);
animate.setDuration(700);
animate.setFillAfter(真正的);
target.startAnimation(动画);
 

  

使用XML的方式

scale.xml (在RES将这个/阿尼姆文件夹)

 < XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:fillAfter =真正的>

    <规模
        机器人:时间=400
        机器人:fillAfter =真
        机器人:fromXScale =1.0
        机器人:fromYScale =1.0
        机器人:pivotX =0%
        机器人:pivotY =0%
        机器人:toXScale =2.0
        机器人:toYScale =1.0>
    < /规模与GT;

< /集>
 

的Java code:

 动画动画= AnimationUtils.loadAnimation(Anims.this,R.anim.scale);
mEdittext.startAnimation(动画);
 

I want to make an edittext which aligns in its parent's left and when users click it, edittext's width'll increase to right side. Here is the code that i used. But when animation ended, edittext width come to first size.
Can any one help me.?
And is there any solution to set "fillparent" to width's final size in animation?

Animation scaleAnimation = new ScaleAnimation(0, -500, 1, 1);
scaleAnimation.setDuration(750);
editText.startAnimation(scaleAnimation);

I added scaleAnimation.setFillAfter(true); before animation starts but i get this;

After 750ms, edittext is going to its first width.

解决方案

This will definitely work for you.

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 (Put this in res/anim folder)

<?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 Code:

Animation anim = AnimationUtils.loadAnimation(Anims.this, R.anim.scale);
mEdittext.startAnimation(anim);

这篇关于EDITTEXT变化幅度动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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