각 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.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;
			}
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {

		}
	}
}  


좌표값에 따라 좌측위에서 우측 아래로 사선으로 이동



+ Recent posts