您好,登錄后才能下訂單哦!
項(xiàng)目開發(fā)偶爾會用到動畫,每次都得找以前的代碼復(fù)制,太麻煩了,但又記不住,只好寫在這.
ObjectAnimator.ofFloat(view, "translationX", 0, 50, -50, 0).setDuration(duration).start();//位移 ObjectAnimator.ofFloat(view, "translationY", 0, 50, -50, 0).setDuration(duration).start(); ObjectAnimator.ofFloat(view, "scaleX", 1, 2, 1).setDuration(duration).start();//縮放 ObjectAnimator.ofFloat(view, "scaleY", 1, 2, 1).setDuration(duration).start(); ObjectAnimator.ofFloat(view, "alpha", 1, 0, 1).setDuration(duration).start();//透明度 ObjectAnimator.ofFloat(view, "rotationX", 0, 180, 0).setDuration(duration).start();//翻轉(zhuǎn) ObjectAnimator.ofFloat(view, "rotationY", 0, 180, 0).setDuration(duration).start(); ObjectAnimator.ofFloat(view, "rotation", 0, 180, 0).setDuration(duration).start();//旋轉(zhuǎn) ViewHelper.setPivotX(view, view.getWidth() / 2f);//設(shè)置動畫基點(diǎn) ViewHelper.setPivotY(view, view.getHeight() / 2f);
以上就是比較常用的nineold,但是偶爾遇到組合的,這樣就比較省事
AnimatorSet animator = new AnimatorSet(); animator.playTogether( ObjectAnimator.ofFloat(p_w_picpath, "rotation", 0, 1080), ObjectAnimator.ofFloat(p_w_picpath, "translationX", 0, 180), ObjectAnimator.ofFloat(p_w_picpath, "translationY", 0, -180), ObjectAnimator.ofFloat(p_w_picpath, "scaleX", 1, 0), ObjectAnimator.ofFloat(p_w_picpath, "scaleY", 1, 0) ObjectAnimator.ofFloat(p_w_picpath, "alpha", 1, 0.25f, 1) ); animator.setDuration(5 * 1000).start();
今天做一個(gè)添加商品到購物車時(shí) 商品圖片旋轉(zhuǎn) 縮小 位移 到指定的購物車圖標(biāo)位置,用的屬性動畫,很麻煩,動畫執(zhí)行順序如果弄亂了,位移軌跡會出問題的.大概記錄一下,以免忘了
int[] endLocation = new int[2]; topSpcart.getLocationInWindow(endLocation);// shopCart是那個(gè)購物車 // 計(jì)算位移 int endX = endLocation[0] - startLocation[0] ;// 動畫位移的X坐標(biāo) int endY = endLocation[1] - startLocation[1];// 動畫位移的y坐標(biāo) RotateAnimation rotateAnimation = new RotateAnimation(0, 1080, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ScaleAnimation scaleAnimation =new ScaleAnimation(1, 0, 1, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); TranslateAnimation translateAnimation = new TranslateAnimation(0,endX, 0, endY); // translateAnimation.setInterpolator(new LinearInterpolator());//動畫加速器 // translateAnimation.setInterpolator(new AccelerateInterpolator()); // translateAnimation.setRepeatCount(0);// 動畫重復(fù)執(zhí)行的次數(shù) // translateAnimation.setFillAfter(true);//動畫結(jié)束留在原位置 AnimationSet set = new AnimationSet(false); set.setFillAfter(true); set.addAnimation(rotateAnimation);//旋轉(zhuǎn) set.addAnimation(scaleAnimation);//縮放 set.addAnimation(translateAnimation);//位移 set.setDuration(1000);// 動畫的執(zhí)行時(shí)間 view.startAnimation(set); // 動畫監(jiān)聽事件 set.setAnimationListener(new AnimationListener() { // 動畫的開始 @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } // 動畫的結(jié)束 @Override public void onAnimationEnd(Animation animation) { } });
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。