項(xiàng)目開發(fā)偶爾會(huì)用到動(dòng)畫,每次都得找以前的代碼復(fù)制,太麻煩了,但又記不住,只好寫在這.
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供眉山網(wǎng)站建設(shè)、眉山做網(wǎng)站、眉山網(wǎng)站設(shè)計(jì)、眉山網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、眉山企業(yè)網(wǎng)站模板建站服務(wù),十多年眉山做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
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è)置動(dòng)畫基點(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)位置,用的屬性動(dòng)畫,很麻煩,動(dòng)畫執(zhí)行順序如果弄亂了,位移軌跡會(huì)出問題的.大概記錄一下,以免忘了
int[] endLocation = new int[2]; topSpcart.getLocationInWindow(endLocation);// shopCart是那個(gè)購物車 // 計(jì)算位移 int endX = endLocation[0] - startLocation[0] ;// 動(dòng)畫位移的X坐標(biāo) int endY = endLocation[1] - startLocation[1];// 動(dòng)畫位移的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());//動(dòng)畫加速器 // translateAnimation.setInterpolator(new AccelerateInterpolator()); // translateAnimation.setRepeatCount(0);// 動(dòng)畫重復(fù)執(zhí)行的次數(shù) // translateAnimation.setFillAfter(true);//動(dòng)畫結(jié)束留在原位置 AnimationSet set = new AnimationSet(false); set.setFillAfter(true); set.addAnimation(rotateAnimation);//旋轉(zhuǎn) set.addAnimation(scaleAnimation);//縮放 set.addAnimation(translateAnimation);//位移 set.setDuration(1000);// 動(dòng)畫的執(zhí)行時(shí)間 view.startAnimation(set); // 動(dòng)畫監(jiān)聽事件 set.setAnimationListener(new AnimationListener() { // 動(dòng)畫的開始 @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } // 動(dòng)畫的結(jié)束 @Override public void onAnimationEnd(Animation animation) { } });
文章標(biāo)題:Android屬性動(dòng)畫備忘nineold
分享網(wǎng)址:http://jinyejixie.com/article16/jpdidg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站內(nèi)鏈、網(wǎng)站排名、商城網(wǎng)站、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)