main.xml
<?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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
	
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
    
    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        
        <ImageView 
            android:layout_width="200dp"
       		android:layout_height="200dp"
       		android:src="@drawable/red"
            />
        <ImageView 
            android:layout_width="200dp"
       		android:layout_height="200dp"
       		android:src="@drawable/yellow"
            />
        <ImageView 
            android:layout_width="200dp"
       		android:layout_height="200dp"
       		android:src="@drawable/blue"
            />
        <ImageView 
            android:layout_width="200dp"
       		android:layout_height="200dp"
       		android:src="@drawable/black"
            />
        
    </ViewFlipper>

</LinearLayout>
FlipperActivity.java
package com.gusfree.viewflipper;

import android.app.Activity;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ViewFlipper;

public class ViewFlipperActivity extends Activity {
	ViewFlipper flip;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		flip=(ViewFlipper)findViewById(R.id.viewFlipper1);

		TranslateAnimation ani1=new TranslateAnimation(0, 320, 100, 100);
		ani1.setDuration(1000);

		Animation utils1=AnimationUtils.makeInAnimation(this, true);
		Animation utils2=AnimationUtils.makeOutAnimation(this, true);

		flip.setInAnimation(utils1); 
		flip.setInAnimation(utils2); 


		Listener listener=new Listener();
		findViewById(R.id.button1).setOnClickListener(listener);
		findViewById(R.id.button2).setOnClickListener(listener);
	}

	class Listener implements OnClickListener{

		@Override
		public void onClick(View v) {
			if(v.getId()==R.id.button1){
				flip.startFlipping();
			}else{
				flip.stopFlipping();
			}

		}

	}
}


맥에서 실행 시켜본 이클립스~~~ 저 이미지가 바뀌면선 오른쪽으로 움직인다~~



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

10일차 BroadcastReceiver  (0) 2012.05.09
10일차 Alarm  (0) 2012.05.09
9일차 LifeCycle  (0) 2012.05.08
9일차 SQLite 연동하기(naver 메모장)  (0) 2012.05.08
9일차 복습  (0) 2012.05.08

+ Recent posts