각 xml 세팅은 여기서 참조 하세요

http://gusfree.tistory.com/admin/entry/post/?id=803 

package com.gusfree.twinanimation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

public class TwinAnimaionActivity extends Activity {
	Spinner spinner;
	ImageView imageView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		spinner=(Spinner)findViewById(R.id.spinner1);
		imageView=(ImageView)findViewById(R.id.imageView1);

		ArrayAdapter adapter=
				ArrayAdapter.createFromResource(this,R.array.twin,
						android.R.layout.simple_spinner_item);

		adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
		spinner.setAdapter(adapter);

		spinner.setOnItemSelectedListener(new Lisetener());
	}
	class Lisetener implements OnItemSelectedListener{

		@Override
		public void onItemSelected(AdapterView<?> parent, View view, int position,
				long id) {
			Toast.makeText(TwinAnimaionActivity.this, position+"번째", 0).show();

			switch(position){
			//이동애니메이션 x시작점 x끝점 y시작점 y끝점
			//왼쪽 위(0,0) 오른쪽 아래 (320,460)
			case 0: TranslateAnimation ani0 = new TranslateAnimation(0, 320, 50, 50);

			ani0.setDuration(2000);
			imageView.startAnimation(ani0);
			spinner.startAnimation(ani0);
			
			break;

			case 1: TranslateAnimation ani1 = new TranslateAnimation(
					Animation.RELATIVE_TO_PARENT,0
					,Animation.RELATIVE_TO_PARENT,1
					,Animation.RELATIVE_TO_PARENT,0
					,Animation.RELATIVE_TO_PARENT,1);
			ani1.setDuration(2000);
			imageView.startAnimation(ani1);
			spinner.startAnimation(ani1);
			
			break;
			
			case 2: AlphaAnimation ani2 = new AlphaAnimation(1,0);//fade out
			ani2.setDuration(2000);
			imageView.startAnimation(ani2);
			spinner.startAnimation(ani2);
			
			break;
			                                        //~각도,->각도,x중심,y중심
			case 3: RotateAnimation ani3=new RotateAnimation(-360, 400,1,1);
			ani3.setDuration(2000);
			imageView.startAnimation(ani3);
			spinner.startAnimation(ani3);
			
			break;
			}
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}
}    

농구로 치면 내가 잘하는 피벗 플레이다..ㅎㅎㅎㅎㅎ





case 3: RotateAnimation ani3=new RotateAnimation(-360, 400,1,1);
			ani3.setDuration(2000);
			ani3.setFillAfter(true);//끝난 상태로 끝
			ani3.setRepeatCount(2)
			imageView.startAnimation(ani3);
			spinner.startAnimation(ani3);


setFillAfter 사용하는경우 마지막에 이렇게 끝난다.

setRepeatCount 반복횟수


'Android > 2012.04월 강좌' 카테고리의 다른 글

7일차 AnimationSet  (0) 2012.05.04
7일차 ScaleAnimation  (0) 2012.05.04
7일차 AlphaAnimation  (0) 2012.05.04
7일차 TranslateAnimation  (0) 2012.05.04
7일차 복습  (0) 2012.05.04

+ Recent posts