각 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.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,1
					,Animation.RELATIVE_TO_PARENT,1
					,Animation.RELATIVE_TO_PARENT,0
					,Animation.RELATIVE_TO_PARENT,1);
			ani1.setDuration(100);
			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;
			}
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}
}    

이미지뷰와 스피너가 점점 살아진다(Fade Out)


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

7일차 ScaleAnimation  (0) 2012.05.04
7일차 RotateAnimation(setFillAfter,setRepeatCount)  (0) 2012.05.04
7일차 TranslateAnimation  (0) 2012.05.04
7일차 복습  (0) 2012.05.04
6일차 TwinAnimaion  (0) 2012.05.03

+ Recent posts