午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

android 實(shí)現(xiàn)控件左右或上下抖動教程

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

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

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

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

<?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軸起點(diǎn)抖動位置 toXDelta:x軸終點(diǎn)抖動位置 duration:循環(huán)播放的時間 interpolator:循環(huán)不放設(shè)置(次數(shù)) --></translate>

(2)cycle.xml文件,控制循環(huán)次數(shù)

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

最后給你的控件設(shè)置改動畫屬性

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

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

2、個人碰到一個問題就是在Activity實(shí)現(xiàn)監(jiān)聽中添加動畫效果第一次沒有反應(yīng),不知道為什么

補(bǔ)充知識:Android 抖動提示動畫

左右抖動

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

重復(fù)左右抖動

Animation translateAnimation = new TranslateAnimation(-20, 20, 0, 0);translateAnimation.setDuration(100);//每次時間translateAnimation.setRepeatCount(10);//重復(fù)次數(shù)/**倒序重復(fù)REVERSE 正序重復(fù)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);//重復(fù)次數(shù)/**倒序重復(fù)REVERSE 正序重復(fù)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 實(shí)現(xiàn)控件左右或上下抖動教程就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 国产精品1234区 | 中文字幕在线不卡视频 | 97超碰人人草 | 日韩在线二区 | 精品国产乱码久久久久久蜜臀网站 | 日韩欧美一二三区 | 91网址入口 | 高清成人综合 | 国产精品1页 | 欧美图片一区二区 | 日韩在线视频看看 | 在线成人观看 | 亚洲国产精品久久久久久久 | 日韩一级二级三级 | 超碰.com | 色综合一区二区三区 | 国产一级自拍 | 精品日本一区二区三区在线观看 | 国产在线观看免费视频今夜 | 猫咪av在线 | 四虎福利视频 | 国产一区在线视频 | 福利网在线观看 | 日本亚洲视频 | 好吊色视频一区二区 | 亚洲精选一区二区三区 | 日韩第一区| 国产成人精品综合 | 国产一区二区三区四区在线 | 日韩欧美高清 | av中文资源在线 | 综合激情婷婷 | 影音先锋av影院 | 中文字幕观看在线 | 黄色av免费 | 人人干在线 | 91丁香| 狠狠操在线 | 国产成人麻豆 | 日韩高清国产一区在线 | 热久久精品 |