如何使编辑文本在动画类型中从左到右移动或反之亦然?[英] how to make edittext move from left to right or vice versa in animation type

本文是小编为大家收集整理的关于如何使编辑文本在动画类型中从左到右移动或反之亦然?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我已经完成了edittext onclick按钮的验证,如果它是空的,则显示一个吐司,说明特定字段为空,并添加了Edittext将其从左到右移动,反之亦然是动画形式,并有助于制作应用吸引力是可能的吗?如果是的话,请提前帮助我感谢

推荐答案

以anim/shake.xml创建和写入以下内容:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
    android:interpolator="@anim/cycle_7" />

以anim/cycle_7.xml创建和写入以下:

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

现在使用动画类通过传递参数来为任何视图进行动画.通过传递任何视图来调用此方法

public void onShake(View v, String your_msg) {
    Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
    findViewById(R.id.pw).startAnimation(shake);
    Toast.makeText(this, your_msg, Toast.LENGTH_SHORT).show();
}

本文地址:https://www.itbaoku.cn/post/102583.html

问题描述

i have done validation for edittext onclick of button and if it is empty will show a toast saying particular field empty and in addition want edittext to get it moved from left to right and vice versa as an animated form and will help to make app attractive Is it possible?? if so please help me thanks in advance

推荐答案

Create and Write following into anim/shake.xml:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromXDelta="0" android:toXDelta="10" android:duration="1000"
    android:interpolator="@anim/cycle_7" />

Create and Write following into anim/cycle_7.xml:

<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

now Use Animation class to animate any view by passing in argument. Call this method by passing any view

public void onShake(View v, String your_msg) {
    Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
    findViewById(R.id.pw).startAnimation(shake);
    Toast.makeText(this, your_msg, Toast.LENGTH_SHORT).show();
}