android - Edittext 随动画改变宽度

标签 android xml android-edittext android-animation

我想制作一个在其父级左侧对齐的编辑文本,当用户单击它时,编辑文本的宽度将增加到右侧。这是我使用的代码。但是当动画结束时,edittext 宽度达到第一个尺寸。
有人能帮我吗?
有什么解决方案可以在动画中将“fillparent”设置为宽度的最终尺寸吗?

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

我在动画开始之前添加了 scaleAnimation.setFillAfter(true); 但我明白了; enter image description here

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/

相关文章:

java - 针对包含 xsd :import without location 的 XSD 验证 XML

java - 使用 Jersey 发布到服务 - "A message body writer ... was not found"

android-edittext - editText 获取文本 kotlin

android - 如何防止 VideoView/MediaPlayer 停止其他应用程序的音频?

java - 如何在android studio上创建一个单独的类

2.3.4 更新后 Android 通信错误

android - 在 Android 中使用 Glide 显示图像。看不到任何东西

xml - 列出文档元素的所有子节点

android - 如何将 Material 设计风格设置为禁用 EditText (android)?

java - Android - 获取光标在当前行的位置。