亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

android 實現控件左右或上下抖動教程

瀏覽:42日期:2022-09-25 17:50:17

差不多一年前在自己的項目中用過這效果,雖然很簡單,但還是寫寫。

1、首先在你的res目錄下新建anim子目錄,并在anim目錄下新建兩個文件:

(1)shake.xml文件(位移/平移:translate),設置起始的位移范圍、效果時間、循環次數

<?xml version='1.0' encoding='utf-8'?><translate xmlns:android='http://schemas.android.com/apk/res/android' android:fromXDelta='0' android:toXDelta='10' android:duration='500' android:interpolator='@anim/share_cycle'> <!--. fromXDelta:x軸起點抖動位置 toXDelta:x軸終點抖動位置 duration:循環播放的時間 interpolator:循環不放設置(次數) --></translate>

(2)cycle.xml文件,控制循環次數

<?xml version='1.0' encoding='utf-8'?><cycleInterpolator xmlns:android='http://schemas.android.com/apk/res/android' android:cycles='2'><!--. 循環次數 --></cycleInterpolator><!--. 循環播放 -->

最后給你的控件設置改動畫屬性

Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);ivShake.startAnimation(shake);

這里ivShake是ImageView,就是這么簡單。

2、個人碰到一個問題就是在Activity實現監聽中添加動畫效果第一次沒有反應,不知道為什么

補充知識: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 正序重復RESTART**/translateAnimation.setRepeatMode(Animation.REVERSE);nope.startAnimation(translateAnimation); public static void Shakeview( View view) { Animation translateAnimation = new TranslateAnimation(-10, 10, 0, 0); translateAnimation.setDuration(50);//每次時間 translateAnimation.setRepeatCount(10);//重復次數/**倒序重復REVERSE 正序重復RESTART**/ translateAnimation.setRepeatMode(Animation.REVERSE); view.startAnimation(translateAnimation); }

左右上下抖動

ObjectAnimator animator = tada(clickMe);animator.setRepeatCount(ValueAnimator.INFINITE);animator.start(); public static ObjectAnimator tada(View view) { return tada(view, 2f);} public static ObjectAnimator tada(View view, float shakeFactor) { PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe(View.SCALE_X, Keyframe.ofFloat(0f, 1f), Keyframe.ofFloat(.1f, .9f), Keyframe.ofFloat(.2f, .9f), Keyframe.ofFloat(.3f, 1.1f), Keyframe.ofFloat(.4f, 1.1f), Keyframe.ofFloat(.5f, 1.1f), Keyframe.ofFloat(.6f, 1.1f), Keyframe.ofFloat(.7f, 1.1f), Keyframe.ofFloat(.8f, 1.1f), Keyframe.ofFloat(.9f, 1.1f), Keyframe.ofFloat(1f, 1f) ); PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe(View.SCALE_Y, Keyframe.ofFloat(0f, 1f), Keyframe.ofFloat(.1f, .9f), Keyframe.ofFloat(.2f, .9f), Keyframe.ofFloat(.3f, 1.1f), Keyframe.ofFloat(.4f, 1.1f), Keyframe.ofFloat(.5f, 1.1f), Keyframe.ofFloat(.6f, 1.1f), Keyframe.ofFloat(.7f, 1.1f), Keyframe.ofFloat(.8f, 1.1f), Keyframe.ofFloat(.9f, 1.1f), Keyframe.ofFloat(1f, 1f) ); PropertyValuesHolder pvhRotate = PropertyValuesHolder.ofKeyframe(View.ROTATION, Keyframe.ofFloat(0f, 0f), Keyframe.ofFloat(.1f, -3f * shakeFactor), Keyframe.ofFloat(.2f, -3f * shakeFactor), Keyframe.ofFloat(.3f, 3f * shakeFactor), Keyframe.ofFloat(.4f, -3f * shakeFactor), Keyframe.ofFloat(.5f, 3f * shakeFactor), Keyframe.ofFloat(.6f, -3f * shakeFactor), Keyframe.ofFloat(.7f, 3f * shakeFactor), Keyframe.ofFloat(.8f, -3f * shakeFactor), Keyframe.ofFloat(.9f, 3f * shakeFactor), Keyframe.ofFloat(1f, 0) ); return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate). setDuration(1000);}

以上這篇android 實現控件左右或上下抖動教程就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 久久久久国产成人精品亚洲午夜 | 国产人成久久久精品 | 91精品国产露脸在线观看 | 日韩人成 | 中文字幕欧美日韩久久 | 黄色视屏免费看 | 欧洲无线区一二区 | 久久综合免费视频 | 黄色一级免费网站 | 成人看片又黄又爽 | 日韩免费观看 | 亚洲高清一区二区三区久久 | 手机看片www xiao2b cm | 免费看的黄色大片 | 九九热亚洲精品综合视频 | 国产极品嫩模大尺度福利视频 | 久久久社区 | 狠狠狠色丁香婷婷综合久久五月 | 国产成人免费永久播放视频平台 | 国产尤物视频在线 | 国产成人h片视频在线观看 国产成人lu在线视频 | 欧美一级毛片大片免费播放 | 美女久久久 | 色综合久久六月婷婷中文字幕 | 国产成人精品综合网站 | 久久成人国产精品免费 | 91精品免费不卡在线观看 | 国产成人在线免费观看 | 国产精品69白浆在线观看免费 | 日韩一区二区视频 | 亚洲午夜片 | 国产成人精品久久免费动漫 | 日韩丝袜在线 | 五月久久亚洲七七综合中文网 | 老年人一级特黄aa大片 | 大狠狠大臿蕉香蕉大视频 | 国产欧美亚洲三区久在线观看 | 免费中文字幕乱码电影麻豆网 | 伊人中文字幕在线 | 欧美α一级毛片 | 日本一极毛片兔费看 |