首页 > 其他分享 >食神摇摇中图片的晃动效果

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

时间:2023-04-06 21:35:32浏览次数:49  
标签:食神 晃动 CycleInterpolator translateAnimation 摇摇 Animation shake new animation





可以是这样子实现滴:

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;  
    }


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

  • 大小: 3.5 KB
  • 查看图片附件

标签:食神,晃动,CycleInterpolator,translateAnimation,摇摇,Animation,shake,new,animation
From: https://blog.51cto.com/u_5454003/6174169

相关文章

  • Foursquare新功能:摇摇手机,签到轻松搞定
    有人可能会觉得之前Foursquare的签到功能有些麻烦,得慢慢掏出手机,搜出当前地点,点击“签到”才算完成。Foursquare推出的新功能就简单多啦,该公司利用NFC技术,用户只要摇一摇手机,就能自动对当前地点进行签到,这样用户也不那么容易忘记签到,也不会因为觉得麻烦而不对酒店咖啡厅的进行......
  • Android实战简易教程-第三十三枪(自定义View实现控件晃动提示效果)
    用户登录注册页面,在进行数据提交之前我们一般都要进行初步判断,判断用户是否输入内容,在内容为空时我们一般进行Toast提示,今天我们实现另一种提示效果–控件晃动。接着上一......
  • 加入购物车抛小球和购物车晃动
    抛出小球加到地方对应元素晃动(加入购物车动画)/****横向抛小球到购物车*@paramaddBtnDom增加按钮的dom元素或者选择器,初始位置*@paramshopCarDom购物车的d......