Android動畫Animation之Tween用代碼實現動畫效果

來源:互聯網
上載者:User

1、跟上一遍部落格一樣,請參考Android動畫效果Animation之Tween實現簡單動畫;

接下來直接java代碼實現如何?動畫:

定義

private Animation animation_alpha,animation_scale,animation_translate,animation_rotate;private AnimationSet animationSet;

分別是透明度動畫、旋轉動畫、尺寸伸縮動畫、移動動畫

具體實現代碼如下:

private void initAnimation() {//透明度控制動畫效果 alphaanimation_alpha=new AlphaAnimation(0.1f,1.0f);//第一個參數fromAlpha為 動畫開始時候透明度//第二個參數toAlpha為 動畫結束時候透明度animation_alpha.setRepeatCount(-1);//設定迴圈animation_alpha.setDuration(5000);//設定時間期間為 5000毫秒// 旋轉效果rotateanimation_rotate = new RotateAnimation(0, -720,RotateAnimation.RELATIVE_TO_SELF, 0.5f,RotateAnimation.RELATIVE_TO_SELF, 0.5f);  //第一個參數fromDegrees為動畫起始時的旋轉角度 //第二個參數toDegrees為動畫旋轉到的角度  //第三個參數pivotXType為動畫在X軸相對於物件位置類型 //第四個參數pivotXValue為動畫相對於物件的X座標的開始位置  //第五個參數pivotXType為動畫在Y軸相對於物件位置類型 //第六個參數pivotYValue為動畫相對於物件的Y座標的開始位置animation_rotate.setRepeatCount(-1);animation_rotate.setDuration(5000);//設定時間期間為 5000毫秒//尺寸伸縮動畫效果 scaleanimation_scale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);//第一個參數fromX為動畫起始時 X座標上的伸縮尺寸    //第二個參數toX為動畫結束時 X座標上的伸縮尺寸     //第三個參數fromY為動畫起始時Y座標上的伸縮尺寸    //第四個參數toY為動畫結束時Y座標上的伸縮尺寸  /*說明:                    以上四種屬性值          0.0表示收縮到沒有       1.0表示正常無伸縮                        值小於1.0表示收縮                     值大於1.0表示放大*///第五個參數pivotXType為動畫在X軸相對於物件位置類型  //第六個參數pivotXValue為動畫相對於物件的X座標的開始位置//第七個參數pivotXType為動畫在Y軸相對於物件位置類型   //第八個參數pivotYValue為動畫相對於物件的Y座標的開始位置animation_scale.setRepeatCount(-1);animation_scale.setDuration(5000);//設定時間期間為 5000毫秒//移動動畫效果translateanimation_translate=new TranslateAnimation(-20f,300f,-20f,300f);//第一個參數fromXDelta為動畫起始時 X座標上的移動位置    //第二個參數toXDelta為動畫結束時 X座標上的移動位置      //第三個參數fromYDelta為動畫起始時Y座標上的移動位置 //第三個參數toYDelta為動畫結束時Y座標上的移動位置 animation_translate.setRepeatCount(-1);//設定動畫執行多少次,如果是-1的話就是一直重複animation_translate.setDuration(5000);//設定時間期間為 5000毫秒animationSet=new AnimationSet(true);animationSet.addAnimation(animation_alpha);//透明度animationSet.addAnimation(animation_rotate);//旋轉animationSet.addAnimation(animation_scale);//尺寸伸縮animationSet.addAnimation(animation_translate);//移動image.startAnimation(animationSet);//開始播放}
AnimationSet這個類是:

Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore),
the values of AnimationSet override the child values.

意思是:代表一群動畫應該一同玩耍。轉變是由每個個體的動畫在一起,成為一個單一的變換。如果AnimationSet設定任何屬性,其子女也設定(例如,期間或fillBefore)的值AnimationSet推翻這孩子的價值觀。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.