안드로이드

 

 

 

기울기 효과

 

 

 

 

class SkewAnim
  class SkewAnim extends Animation {
        String action = "LinearInterpolator";

        public SkewAnim(String action) {
            this.action = action;
        }

        //애니메이션 초기화
        @Override
        public void initialize(int width, int height, int parentWidth, int parentHeight) {
            super.initialize(width, height, parentWidth, parentHeight);
            setDuration(3000); //애니메이션 작동 시간

            //애니메이션 효과
            if (action.equals("LinearInterpolator")) {
                setInterpolator(new LinearInterpolator()); //일정하게

            } else if (action.equals("AccelerateInterpolator")) {
                setInterpolator(new AccelerateInterpolator()); //점점빠르게

            } else if (action.equals("DecelerateInterpolator")) {
                setInterpolator(new DecelerateInterpolator()); //점점 느리게

            } else if (action.equals("AccelerateDecelerateInterpolator")) {
                setInterpolator(new AccelerateDecelerateInterpolator()); //점점빠르게 + 점점 느리게

            } else if (action.equals("AnticipateInterpolator")) {
                setInterpolator(new AnticipateInterpolator()); //시작위치에서 조금 뒤로 이동했다가 이동


            } else if (action.equals("OvershootInterpolator")) {
                setInterpolator(new OvershootInterpolator()); //도착위치를 조금 지나쳤다가 이동

            } else if (action.equals("AnticipateOvershootInterpolator")) {

                //변경이 역방향으로 시작된 후 앞으로 나아가다가 오버되는 보간에서
                //목표 값과 마지막으로 최종 값으로 돌아갑니다.
                setInterpolator(new AnticipateOvershootInterpolator()); //

            } else if (action.equals("BounceInterpolator")) {
                setInterpolator(new BounceInterpolator()); //도착 위치에서 튕기는 효과
            }

        }


        //애니메이션 적용
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            //@param interpolatedTime  표준시간 (0.0 to 1.0)
            //@param Transformation 현재 변형 처리 객체 t

            //Transformation 객체로부터 이미지 변형 처리를 위한
            //매트릭스 객체 생성
            Matrix matrix = t.getMatrix();

            //기울기 설정( x축 기울기 , y축 기울기)
            //기울기 x 시간
            //-0.5f 왼쪽으로
            matrix.setSkew(-0.5f * interpolatedTime, 0);


        }


    }

 

 

카메라 효과

 

  class CameraAnim extends Animation {

        float cx, cy; //카메라의 좌표
        String action = "LinearInterpolator";

        public CameraAnim(String action) {
            this.action = action;
        }

        //애니메이션 초기화
        @Override
        public void initialize(int width, int height, int parentWidth, int parentHeight) {
            super.initialize(width, height, parentWidth, parentHeight);
            //카메라의 중심 좌표
            cx = width/10;
            cy = height/10;
            Log.i("test", "  width : " + width+ " : height : " +height);
            //애니메이션 작동 시간 설정
            setDuration(3000);

            //애니메이션 효과
            if (action.equals("LinearInterpolator")) {
                setInterpolator(new LinearInterpolator()); //일정하게

            } else if (action.equals("AccelerateInterpolator")) {
                setInterpolator(new AccelerateInterpolator()); //점점빠르게

            } else if (action.equals("DecelerateInterpolator")) {
                setInterpolator(new DecelerateInterpolator()); //점점 느리게

            } else if (action.equals("AccelerateDecelerateInterpolator")) {
                setInterpolator(new AccelerateDecelerateInterpolator()); //점점빠르게 + 점점 느리게

            } else if (action.equals("AnticipateInterpolator")) {
                setInterpolator(new AnticipateInterpolator()); //시작위치에서 조금 뒤로 이동했다가 이동


            } else if (action.equals("OvershootInterpolator")) {
                setInterpolator(new OvershootInterpolator()); //도착위치를 조금 지나쳤다가 이동

            } else if (action.equals("AnticipateOvershootInterpolator")) {

                //변경이 역방향으로 시작된 후 앞으로 나아가다가 오버되는 보간에서
                //목표 값과 마지막으로 최종 값으로 돌아갑니다.
                setInterpolator(new AnticipateOvershootInterpolator()); //

            } else if (action.equals("BounceInterpolator")) {
                setInterpolator(new BounceInterpolator()); //도착 위치에서 튕기는 효과
            }


        }


        //애니메이션 적용
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            //카메라 객체 생성
            Camera camera = new Camera();
            //x축 회전 설정 (각도 x 애니메이션 시간)
           // camera.rotateX(360*interpolatedTime);
            camera.rotateY(360*interpolatedTime);
            //camera.rotateZ(360*interpolatedTime);

            //매트릭스 객체(이미지 변형 처리 객체)
            Matrix matrix=t.getMatrix();
            camera.getMatrix(matrix);

            //카메라를 회전하기 전의 중심 좌표를 설정
            //matrix.preTranslate(cx, cy); //-는 현재 뒤에 있다.
            matrix.postTranslate(cx,cy);

        }


    }

 

 

class CustomActivity
package com.example.choi.ex08_animation;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.AnticipateOvershootInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.Transformation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.android.gms.common.api.GoogleApiClient;

public class CustomActivity extends AppCompatActivity {

    Button btnSkew, btnCamera;

    ImageView image1;

    private GoogleApiClient client;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom);

        //2.객체 생성
        btnSkew = (Button) findViewById(R.id.btnSkew);
        btnCamera = (Button) findViewById(R.id.btnCamera);
        image1 = (ImageView) findViewById(R.id.image1);


        btnSkew.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //3.애니메이션 적용
                image1.startAnimation(new SkewAnim("LinearInterpolator"));
            }
        });


        btnCamera.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                image1.startAnimation(new CameraAnim("LinearInterpolator"));
            }
        });


    }

    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.btn1:
                //3.애니메이션 적용
                Toast.makeText(CustomActivity.this, "LinearInterpolator(일정하게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("LinearInterpolator"));
                break;

            case R.id.btn2:
                Toast.makeText(CustomActivity.this, "AccelerateInterpolator(점점빠르게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("AccelerateInterpolator"));
                break;

            case R.id.btn3:
                Toast.makeText(CustomActivity.this, "DecelerateInterpolator(점점느리게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("DecelerateInterpolator"));
                break;

            case R.id.btn4:
                Toast.makeText(CustomActivity.this, "AccelerateDecelerateInterpolator(점점빠르게 + 점점 느리게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("AccelerateDecelerateInterpolator"));
                break;

            case R.id.btn5:
                Toast.makeText(CustomActivity.this, "AnticipateInterpolator(시작위치에서 조금 뒤로 이동했다가 이동)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("AnticipateInterpolator"));
                break;

            case R.id.btn6:
                Toast.makeText(CustomActivity.this, "OvershootInterpolator(도착위치를 조금 지나쳤다가 이동)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("OvershootInterpolator"));
                break;

            case R.id.btn7:
                Toast.makeText(CustomActivity.this, "AnticipateOvershootInterpolator", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("AnticipateOvershootInterpolator"));
                break;

            case R.id.btn8:
                Toast.makeText(CustomActivity.this, "BounceInterpolator(도착 위치에서 튕기는 효과)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new SkewAnim("BounceInterpolator"));
                break;



            case R.id.btn21:
                //3.애니메이션 적용
                Toast.makeText(CustomActivity.this, "LinearInterpolator(일정하게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("LinearInterpolator"));
                break;

            case R.id.btn22:
                Toast.makeText(CustomActivity.this, "AccelerateInterpolator(점점빠르게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("AccelerateInterpolator"));
                break;

            case R.id.btn23:
                Toast.makeText(CustomActivity.this, "DecelerateInterpolator(점점느리게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("DecelerateInterpolator"));
                break;

            case R.id.btn24:
                Toast.makeText(CustomActivity.this, "AccelerateDecelerateInterpolator(점점빠르게 + 점점 느리게)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("AccelerateDecelerateInterpolator"));
                break;

            case R.id.btn25:
                Toast.makeText(CustomActivity.this, "AnticipateInterpolator(시작위치에서 조금 뒤로 이동했다가 이동)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("AnticipateInterpolator"));
                break;

            case R.id.btn26:
                Toast.makeText(CustomActivity.this, "OvershootInterpolator(도착위치를 조금 지나쳤다가 이동)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("OvershootInterpolator"));
                break;

            case R.id.btn27:
                Toast.makeText(CustomActivity.this, "AnticipateOvershootInterpolator", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("AnticipateOvershootInterpolator"));
                break;

            case R.id.btn28:
                Toast.makeText(CustomActivity.this, "BounceInterpolator(도착 위치에서 튕기는 효과)", Toast.LENGTH_SHORT).show();
                image1.startAnimation(new CameraAnim("BounceInterpolator"));
                break;



        }

    }



    class SkewAnim extends Animation {
        String action = "LinearInterpolator";

        public SkewAnim(String action) {
            this.action = action;
        }

        //애니메이션 초기화
        @Override
        public void initialize(int width, int height, int parentWidth, int parentHeight) {
            super.initialize(width, height, parentWidth, parentHeight);
            setDuration(3000); //애니메이션 작동 시간

            //애니메이션 효과
            if (action.equals("LinearInterpolator")) {
                setInterpolator(new LinearInterpolator()); //일정하게

            } else if (action.equals("AccelerateInterpolator")) {
                setInterpolator(new AccelerateInterpolator()); //점점빠르게

            } else if (action.equals("DecelerateInterpolator")) {
                setInterpolator(new DecelerateInterpolator()); //점점 느리게

            } else if (action.equals("AccelerateDecelerateInterpolator")) {
                setInterpolator(new AccelerateDecelerateInterpolator()); //점점빠르게 + 점점 느리게

            } else if (action.equals("AnticipateInterpolator")) {
                setInterpolator(new AnticipateInterpolator()); //시작위치에서 조금 뒤로 이동했다가 이동


            } else if (action.equals("OvershootInterpolator")) {
                setInterpolator(new OvershootInterpolator()); //도착위치를 조금 지나쳤다가 이동

            } else if (action.equals("AnticipateOvershootInterpolator")) {

                //변경이 역방향으로 시작된 후 앞으로 나아가다가 오버되는 보간에서
                //목표 값과 마지막으로 최종 값으로 돌아갑니다.
                setInterpolator(new AnticipateOvershootInterpolator()); //

            } else if (action.equals("BounceInterpolator")) {
                setInterpolator(new BounceInterpolator()); //도착 위치에서 튕기는 효과
            }

        }


        //애니메이션 적용
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {

            //@param interpolatedTime  표준시간 (0.0 to 1.0)
            //@param Transformation 현재 변형 처리 객체 t

            //Transformation 객체로부터 이미지 변형 처리를 위한
            //매트릭스 객체 생성
            Matrix matrix = t.getMatrix();

            //기울기 설정( x축 기울기 , y축 기울기)
            //기울기 x 시간
            //-0.5f 왼쪽으로
            matrix.setSkew(-0.5f * interpolatedTime, 0);


        }


    }


    class CameraAnim extends Animation {

        float cx, cy; //카메라의 좌표
        String action = "LinearInterpolator";

        public CameraAnim(String action) {
            this.action = action;
        }

        //애니메이션 초기화
        @Override
        public void initialize(int width, int height, int parentWidth, int parentHeight) {
            super.initialize(width, height, parentWidth, parentHeight);
            //카메라의 중심 좌표
            cx = width/10;
            cy = height/10;
            Log.i("test", "  width : " + width+ " : height : " +height);
            //애니메이션 작동 시간 설정
            setDuration(3000);

            //애니메이션 효과
            if (action.equals("LinearInterpolator")) {
                setInterpolator(new LinearInterpolator()); //일정하게

            } else if (action.equals("AccelerateInterpolator")) {
                setInterpolator(new AccelerateInterpolator()); //점점빠르게

            } else if (action.equals("DecelerateInterpolator")) {
                setInterpolator(new DecelerateInterpolator()); //점점 느리게

            } else if (action.equals("AccelerateDecelerateInterpolator")) {
                setInterpolator(new AccelerateDecelerateInterpolator()); //점점빠르게 + 점점 느리게

            } else if (action.equals("AnticipateInterpolator")) {
                setInterpolator(new AnticipateInterpolator()); //시작위치에서 조금 뒤로 이동했다가 이동


            } else if (action.equals("OvershootInterpolator")) {
                setInterpolator(new OvershootInterpolator()); //도착위치를 조금 지나쳤다가 이동

            } else if (action.equals("AnticipateOvershootInterpolator")) {

                //변경이 역방향으로 시작된 후 앞으로 나아가다가 오버되는 보간에서
                //목표 값과 마지막으로 최종 값으로 돌아갑니다.
                setInterpolator(new AnticipateOvershootInterpolator()); //

            } else if (action.equals("BounceInterpolator")) {
                setInterpolator(new BounceInterpolator()); //도착 위치에서 튕기는 효과
            }


        }


        //애니메이션 적용
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            //카메라 객체 생성
            Camera camera = new Camera();
            //x축 회전 설정 (각도 x 애니메이션 시간)
           // camera.rotateX(360*interpolatedTime);
            camera.rotateY(360*interpolatedTime);
            //camera.rotateZ(360*interpolatedTime);

            //매트릭스 객체(이미지 변형 처리 객체)
            Matrix matrix=t.getMatrix();
            camera.getMatrix(matrix);

            //카메라를 회전하기 전의 중심 좌표를 설정
            //matrix.preTranslate(cx, cy); //-는 현재 뒤에 있다.
            matrix.postTranslate(cx,cy);

        }


    }


}




 

 

custom.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/custom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.choi.ex08_animation.CustomActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >


        <Button
            android:text="기울기"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/btnSkew" />

        <Button
            android:text="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn1"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_green_light" />


        <Button
            android:text="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn2"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_blue_light" />


        <Button
            android:text="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn3"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_orange_dark" />


        <Button
            android:text="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn4"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_red_light" />


        <Button
            android:text="5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn5"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_orange_light" />


        <Button
            android:text="6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn6"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="?android:attr/colorPressedHighlight" />


        <Button
            android:text="7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn7"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_purple" />


        <Button
            android:text="8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn8"
            android:layout_weight="1"
            android:onClick="onClick"
            android:background="@android:color/holo_red_light" />


    </LinearLayout>




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/linearLayout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <Button
            android:text="카메라 효과"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:id="@+id/btnCamera" />

        <Button
            android:text="1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn21"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_green_light" />


        <Button
            android:text="2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn22"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_blue_light" />


        <Button
            android:text="3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn23"
            android:layout_weight="1"
            android:alpha="0.5"
            android:onClick="onClick"
            android:background="@android:color/holo_orange_dark" />


        <Button
            android:text="4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn24"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_red_light" />


        <Button
            android:text="5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn25"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_orange_light" />


        <Button
            android:text="6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn26"
            android:layout_weight="1"
            android:alpha="0.5"
            android:onClick="onClick"
            android:background="?android:attr/colorPressedHighlight" />


        <Button
            android:text="7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn27"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_purple" />


        <Button
            android:text="8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn28"
            android:layout_weight="1"
            android:onClick="onClick"
            android:alpha="0.5"
            android:background="@android:color/holo_red_light" />



    </LinearLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/a21"
        android:id="@+id/image1" />


</LinearLayout>

 

 

 

about author

PHRASE

Level 60  머나먼나라

마음은 모든 일의 근본이 된다. 마음은 주(主)가 되어 모든 일을 시킨다. 마음이 악한 일을 생각하면 그 말과 행동도 또한 그러하다. 괴로움은 그를 따라 마치 수레를 따르는 수레바퀴 자국처럼 생겨난다. 몸은 빈 병과 같다. 그러므로 마음이라는 성을 든든히 쌓아 몸에 악마가 침범하지 못하게 해야 한다. -법구경

댓글 ( 4)

댓글 남기기

작성