<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageView1" android:layout_width="300dp" android:layout_height="300dp" android:src="@drawable/ic_launcher" /> <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ToggleButton" android:layout_gravity="right"/> <ToggleButton android:id="@+id/toggleButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ToggleButton" android:layout_gravity="right"/> </LinearLayout>
package com.gusfree.frameAnimation; import android.app.Activity; import android.content.res.Resources; import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageView; import android.widget.ToggleButton; public class FrameAnimationActivity extends Activity { ImageView imageView; ToggleButton toggle; AnimationDrawable ani; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imageView=(ImageView)findViewById(R.id.imageView1); toggle =(ToggleButton)this.findViewById(R.id.toggleButton1); //프레임 에니메이션 객체를 만들자. ani = new AnimationDrawable(); Resources res = getResources();//리소스 가져와라 ani.addFrame(res.getDrawable(R.drawable.red),300);//1000이 1초 ,500=0.5초 ani.addFrame(res.getDrawable(R.drawable.blue),300); ani.addFrame(res.getDrawable(R.drawable.yellow),300); //에니메이션 무한반복 셋팅하자. ani.setOneShot(false); //에니메이션 객체를 이미지뷰에 셋팅하자 imageView.setImageDrawable(ani); toggle.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override //메서드 체크바꼈을 때 public void onCheckedChanged(CompoundButton arg0, boolean isChecked) { if(isChecked){ ani.start(); }else{ ani.stop(); } } }); } }
'Android > 2012.04월 강좌' 카테고리의 다른 글
6일차 TwinAnimaion (0) | 2012.05.03 |
---|---|
6일차 FrameAnimation 2(xml로 만드 애니메이션 이미지뷰 셋팅) (0) | 2012.05.03 |
6일차 Dialog (0) | 2012.05.03 |
6일차 Menu 2 (Option menu) (0) | 2012.05.03 |
6일차 복습 (0) | 2012.05.03 |