ShakeView(通常提示用户那个输入不正确) 几行代码搞定

来源:互联网 发布:PHP代码中常用的方法 编辑:程序博客网 时间:2024/06/07 08:16

用平移动画实现shake

首先讲一下平移动画的使用吧

看一下构造方法

  1. TranslateAnimation(Context context, AttributeSet attrs) :参数2: 是一个属性,基本没怎么用过
  2. TranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) 参数1: 在x轴上,相对于谁 一个是相对于父亲(Animation.RELATIVE_TO_PARENT很少用到) 一个是相对于自己(Animation.RELATIVE_TO_SELF经常用到),参数2: 在x轴上从什么位置开始, 参数3: 在x轴上到什么位置结束 . 剩下的参数就是y轴上的设置了
  3. TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 参数1:在x轴上从什么位置开始,参数2:在x轴上到什么位置结束 参数3.4 分别表示y轴

首先定义个平移动画

    TranslateAnimation translateAnimation = new TranslateAnimation(-10, 10,0,0);//在x轴上从-10px到10px    translateAnimation.setDuration(100);//执行动画时间100ms    translateAnimation.setRepeatCount(3);//执行次数 3次

直接引用平移动画即可

 indViewById(R.id.tv).startAnimation(translateAnimation);  // 开始动画

就这么简单的一个shakeview就成功的造成了

阅读全文
0 0
原创粉丝点击