重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
這篇文章主要介紹android怎么實(shí)現(xiàn)控件左右或上下抖動(dòng),文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:國(guó)際域名空間、網(wǎng)絡(luò)空間、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、蓬溪網(wǎng)站維護(hù)、網(wǎng)站推廣。
Android是一種基于Linux內(nèi)核的自由及開(kāi)放源代碼的操作系統(tǒng),主要使用于移動(dòng)設(shè)備,如智能手機(jī)和平板電腦,由美國(guó)Google公司和開(kāi)放手機(jī)聯(lián)盟領(lǐng)導(dǎo)及開(kāi)發(fā)。
1、首先在你的res目錄下新建anim子目錄,并在anim目錄下新建兩個(gè)文件:
(1)shake.xml文件(位移/平移:translate),設(shè)置起始的位移范圍、效果時(shí)間、循環(huán)次數(shù)
(2)cycle.xml文件,控制循環(huán)次數(shù)
最后給你的控件設(shè)置改動(dòng)畫(huà)屬性
Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake);
ivShake.startAnimation(shake);
這里ivShake是ImageView,就是這么簡(jiǎn)單。
2、個(gè)人碰到一個(gè)問(wèn)題就是在Activity實(shí)現(xiàn)監(jiān)聽(tīng)中添加動(dòng)畫(huà)效果第一次沒(méi)有反應(yīng),不知道為什么
補(bǔ)充知識(shí):Android 抖動(dòng)提示動(dòng)畫(huà)
左右抖動(dòng)
ObjectAnimator animator = ObjectAnimator.ofFloat(textView, "translationX", 0, 100, -100,0); animator.setDuration(200); animator.start();
重復(fù)左右抖動(dòng)
Animation translateAnimation = new TranslateAnimation(-20, 20, 0, 0); translateAnimation.setDuration(100);//每次時(shí)間 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);//每次時(shí)間 translateAnimation.setRepeatCount(10);//重復(fù)次數(shù) /**倒序重復(fù)REVERSE 正序重復(fù)RESTART**/ translateAnimation.setRepeatMode(Animation.REVERSE); view.startAnimation(translateAnimation); }
左右上下抖動(dòng)
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)控件左右或上下抖動(dòng)”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!