標籤:android布局特效
public class MainActivity extends Activity {AlphaAnimation animation_alpha;RotateAnimation animation_rotate;ScaleAnimation animation_scale;TranslateAnimation animation_translate;AnimationSet animationSet;ImageView image;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);image=(ImageView)findViewById(R.id.imageview);//image.setScaleType(ScaleType.FIT_XY);initAnimation();}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, -180,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(3000);//設定時間期間為 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(0,-300,0,0);//第一個參數fromXDelta為動畫起始時 X座標上的移動位置 //第二個參數toXDelta為動畫結束時 X座標上的移動位置 //第三個參數fromYDelta為動畫起始時Y座標上的移動位置 //第三個參數toYDelta為動畫結束時Y座標上的移動位置 //animation_translate.setRepeatCount(-1);//設定動畫執行多少次,如果是-1的話就是一直重複animation_translate.setDuration(3000);//設定時間期間為 5000毫秒animationSet=new AnimationSet(true);//animationSet.addAnimation(animation_alpha);//透明度animationSet.addAnimation(animation_rotate);//旋轉//animationSet.addAnimation(animation_scale);//尺寸伸縮animationSet.addAnimation(animation_translate);//移動image.startAnimation(animationSet);//開始播放}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Android布局特效(一)