public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_number_address_query:
String number = mEtNumber.getText().toString().trim();
if (TextUtils.isEmpty(number)) {
ToastUtil.showToast(getApplicationContext(), "号码不能为空");
mEtNumber.requestFocus();
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
// shake.setInterpolator(new CycleInterpolator(7));
shake.setInterpolator(new OvershootInterpolator(10.0f));
mEtNumber.startAnimation(shake);
return;
}
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:toXDelta="10" />
<!-- <translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXDelta="0"
android:interpolator="@anim/cycle_7"
android:toXDelta="10" /> -->
《shake.xml 文件,在anim文件夹下》
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:cycles="7" />
《在 anim文件夹下 cycle_7.xml》
本文介绍了一种在Android应用中实现视图摇动效果的方法。通过使用自定义动画和过度插值器,可以为输入为空的情况提供视觉反馈,增强用户体验。文中详细展示了如何在按钮点击事件中检查输入字段,并在为空时触发摇动动画。

被折叠的 条评论
为什么被折叠?



