アニメーション

覚え書き

  • アニメーションは初期の状態を基準としてアニメーション後に基準からどれだけ変更するかを指定する。
  • リファレンスとかにPivotってでてくるが、要するに基準(デフォルトの状態)のこと。
  • 基準となる値のデフォルトは(0,0)つまり左上。
  • 中心じゃないので、回転とか拡大するときはアニメーション対象の中心点を求めたりする。
  • 拡大とかは左上が基点になるので、拡大後に右寄りになる。
  • 「+とか-」でデフォルトと相対的な値を指定する



    public void onClickButtonTrans(View v){
    	TranslateAnimation trans;
    	
//   	Parameters
//		fromXDelta	Change in X coordinate to apply at the start of the animation
//		toXDelta	Change in X coordinate to apply at the end of the animation
//		fromYDelta	Change in Y coordinate to apply at the start of the animation
//		toYDelta	Change in Y coordinate to apply at the end of the animation
    	// 下:240
    	trans = new TranslateAnimation(0, 0, 0, 240);
    	trans.setDuration(3000);
    	text.startAnimation(trans);
    }
    
    public void onClickButtonRotation(View v){
    	RotateAnimation rotate;

//    	Parameters
//    	fromDegrees	Rotation offset to apply at the start of the animation.
//    	toDegrees	Rotation offset to apply at the end of the animation.
//    	pivotX	The X coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the left edge.
//    	pivotY	The Y coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the top edge.
    	//回転中心座標:TextViewの真ん中
    	//360度回転
    	rotate = new RotateAnimation(0, 360, text.getWidth() / 2, text.getHeight() / 2);
    	rotate.setDuration(3000);
    	text.startAnimation(rotate);
    }
    
    public void onClickButtonAlfa(View v){
    	AlphaAnimation alfa;
    	
//    	Parameters
//    	fromAlpha	Starting alpha value for the animation, where 1.0 means fully opaque and 0.0 means fully transparent.
//    	toAlpha	Ending alpha value for the animation.
    	//だんだん消える
    	alfa = new AlphaAnimation(1, 0);
    	alfa.setDuration(3000);
    	text.startAnimation(alfa);
    }
    
    public void onClickButtonScale(View v){
    	ScaleAnimation scale;
    	
//    	Parameters
//    	fromX	Horizontal scaling factor to apply at the start of the animation
//    	toX	Horizontal scaling factor to apply at the end of the animation
//    	fromY	Vertical scaling factor to apply at the start of the animation
//    	toY	Vertical scaling factor to apply at the end of the animation
    	//アニメーション終了後の値
    	//左:TextViewの半分、下:90
    	//変更サイズ:縦横2倍 
    	scale = new ScaleAnimation( 1, 2, 1, 2, text.getWidth() / 2, -90);
    	scale.setDuration(3000);
    	text.startAnimation(scale);
    }