각 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.ScaleAnimation;
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;

			//크기 변경 애니메이션
			case 4: ScaleAnimation ani4= new ScaleAnimation(1, 5,1,5,5,5);
			ani4.setDuration(2000);
			imageView.startAnimation(ani4);
			spinner.startAnimation(ani4);
			}
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}
}    

좌표값에 따라 이미지랑 스피너가 커짐


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

7일차 Notification  (0) 2012.05.04
7일차 AnimationSet  (0) 2012.05.04
7일차 RotateAnimation(setFillAfter,setRepeatCount)  (0) 2012.05.04
7일차 AlphaAnimation  (0) 2012.05.04
7일차 TranslateAnimation  (0) 2012.05.04

+ Recent posts