android怎么实现控件左右或上下抖动

  介绍

这篇文章主要介绍android怎么实现控件左右或上下抖动,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

android是什么

android是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。

<强> 1,首先在你的res目录下新建动物子目录,并在动物目录下新建两个文件:

(1)动摇。xml文件(位移/平移:翻译),设置起始的位移范围,效果时间,循环次数

& lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   & lt; translate  xmlns: android=癶ttp://schemas.android.com/apk/res/android"   android:才能fromXDelta=?”;   android:才能toXDelta=?0“;   android:才能持续时间=?00”;   android:才能插入器=癅anim/share_cycle"比;   & lt; !——才能。   ,,,fromXDelta: x轴起点抖动位置   ,,,toXDelta: x轴终点抖动位置   ,,,时间:循环播放的时间   ,,,插入器:循环不放设置(次)数   ,才能在   & lt;/translate>

(2)循环。xml文件,控制循环次数

& lt; ? xml  version=?.0“,编码=皍tf-8" ?比;   & lt; cycleInterpolator  xmlns: android=癶ttp://schemas.android.com/apk/res/android"   android:才能周期=?“祝辞& lt; !——只循环次数,——比;      & lt;/cycleInterpolator> & lt; !——只循环播放,——在

最后给你的控件设置改动画属性

动画=AnimationUtils握手。loadAnimation(这个,R.anim.shake);
ivShake.startAnimation(震动);

这里ivShake是ImageView,就是这么简单。

<强> 2个人碰到一个问题就是在活动实现监听中添加动画效果第一次没有反应,不知道为什么

<强>补充知识: <强> Android抖动提示动画

<强>左右抖动

ObjectAnimator  animator =, ObjectAnimator.ofFloat (textView,“translationX",, 0, 100, -100, 0);   animator.setDuration (200);   animator.start ();

<强>重复左右抖动

Animation  translateAnimation =, new  TranslateAnimation(-20年,20岁,0,0);   translateAnimation.setDuration(100);//每次时间   translateAnimation.setRepeatCount(10);//重复次数/* *倒序重复REVERSE 正序重复重启* */translateAnimation.setRepeatMode (Animation.REVERSE);   nope.startAnimation (translateAnimation);   public 才能static  void  Shakeview(视图),View , {   ,,,Animation  translateAnimation =, new  TranslateAnimation(10 -10年,,,,0,0);   ,,,translateAnimation.setDuration(50);//每次时间   ,,,translateAnimation.setRepeatCount(10);//重复次数/* *倒序重复REVERSE 正序重复重启* */,,,translateAnimation.setRepeatMode (Animation.REVERSE);   ,,,view.startAnimation (translateAnimation);   以前,,}

<强>左右上下抖动

ObjectAnimator  animator =,恩(clickMe);   animator.setRepeatCount (ValueAnimator.INFINITE);   animator.start ();   ,      public  static  ObjectAnimator 恩(View 视图),{   return 才能;恩(看来,,2 f);   }   ,   public  static  ObjectAnimator 恩(View 看来,,float  shakeFactor), {   ,   PropertyValuesHolder 才能;pvhScaleX =, PropertyValuesHolder.ofKeyframe (View.SCALE_X,   ,,,,,Keyframe.ofFloat (0 f,, 1 f),   ,,,,,Keyframe.ofFloat (.9f .1f也),   ,,,,,Keyframe.ofFloat (.9f .2f也),   ,,,,,Keyframe.ofFloat (.3f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.4f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.5f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.6f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.7f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.8f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.9f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (1 f, 1 f)   ,,);   ,   PropertyValuesHolder 才能;pvhScaleY =, PropertyValuesHolder.ofKeyframe (View.SCALE_Y,   ,,,,,Keyframe.ofFloat (0 f,, 1 f),   ,,,,,Keyframe.ofFloat (.9f .1f也),   ,,,,,Keyframe.ofFloat (.9f .2f也),   ,,,,,Keyframe.ofFloat (.3f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.4f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.5f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.6f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.7f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.8f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (.9f, 1.1华氏度),   ,,,,,Keyframe.ofFloat (1 f, 1 f)   ,,);   ,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

android怎么实现控件左右或上下抖动