食神摇摇中图片的晃动效果

系统 1615 0
食神摇摇中图片的晃动效果

可以是这样子实现滴:
    
btn_shake=(ImageView)findViewById(R.id.btn_shake);
startShakeAnimation(btn_shake);

  


    
private void startShakeAnimation(View v){
		int pivot = Animation.RELATIVE_TO_SELF;
		CycleInterpolator interpolator = new CycleInterpolator(3.0f);
		RotateAnimation animation = new RotateAnimation(0, 15, pivot, 0.5f,pivot, 0.5f);
		animation.setStartOffset(4000);
		animation.setDuration(2000);
		animation.setRepeatCount(Animation.INFINITE);
		animation.setInterpolator(interpolator);
		v.startAnimation(animation);
	 }

  


知道CycleInterpolator是干嘛用的就简单了,Api demo里有它的用法,是个摇头效果!

//////////////////////////////////////////////////////////////////////////////

抖动:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="180"
    android:fromDegrees="-2"
    android:pivotX="100%"
    android:pivotY="100%"
    android:repeatCount="infinite"
    android:repeatMode="reverse"
    android:toDegrees="2" />

Animation shake = AnimationUtils.loadAnimation(context, R.anim.shake);
shake.reset();
shake.setFillAfter(true);
image.startAnimation(shake);

摇头效果:
shake.xml
    
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

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

  


cycle_7.xml
    
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

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

  


代码实现:
    
/** 
     * 晃动动画 
     * @param counts 1秒钟晃动多少下 
     * @return 
     */  
    public static Animation shakeAnimation(int counts){  
        Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0);  
        translateAnimation.setInterpolator(new CycleInterpolator(counts));  
        translateAnimation.setDuration(1000);  
        return translateAnimation;  
    }

  

食神摇摇中图片的晃动效果


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论