안드로이드

 

 

 

 

class TweenActivity

 

package com.example.choi.ex08_animation;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class TweenActivity extends AppCompatActivity {

    //1. 변수 선언
    Button button1, button2, button3, button4, button5;
    Animation ani;
    ImageView image1;
    LinearLayout linear1;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tween);
        //2.객체 생성
        button1 =(Button)findViewById(R.id.button1);
        button2=(Button)findViewById(R.id.button2);
        button3=(Button)findViewById(R.id.button3);
        button4=(Button)findViewById(R.id.button4);
        button5=(Button)findViewById(R.id.button5);


        image1=(ImageView)findViewById(R.id.image1);
        linear1=(LinearLayout)findViewById(R.id.tween);

        //3.이벤트 처리
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //애니메이션 객체 생성
                ani = AnimationUtils.loadAnimation(TweenActivity.this, R.anim.translate);
                //애니메이션 시작
                linear1.startAnimation(ani);
            }
        });


        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //애니메이션 객체 생성
                ani=AnimationUtils.loadAnimation(TweenActivity.this, R.anim.rotate);
                //애니메이션 시작
                linear1.startAnimation(ani);
            }
        });

        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ani =AnimationUtils.loadAnimation(TweenActivity.this,
                        R.anim.alpha);
                linear1.startAnimation(ani);
            }
        });

        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ani =AnimationUtils.loadAnimation(TweenActivity.this,
                        R.anim.scale);
                image1.startAnimation(ani);
            }
        });


        button5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ani=AnimationUtils.loadAnimation(TweenActivity.this,
                        R.anim.set);

                image1.startAnimation(ani);
            }
        });


    }



}

 

 

tween.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/tween"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.choi.ex08_animation.TweenActivity">

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

        <Button
            android:text="이동"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:textSize="10sp" />

        <Button
            android:text="회전"
            android:layout_height="wrap_content"
            android:id="@+id/button2"
            android:textSize="10sp"
            android:layout_width="50dp" />

        <Button
            android:text="투명도 조절"
            android:layout_height="wrap_content"
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:textSize="10sp" />

        <Button
            android:text="크기조절"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button4"
            android:textSize="10sp" />

        <Button
            android:text="혼합"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button5"
            android:layout_weight="1"
            android:textSize="10sp" />


    </LinearLayout>



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


</LinearLayout>

 

 

 

 

회전

 

 

translate.xml
<?xml version="1.0" encoding="utf-8"?>
<!--translate.xml-->

<set xmlns:android="http://schemas.android.com/apk/res/android">

<!--

    fromXDelta x축의 시작 위치
    toXDelta x축의 마지막 위치
    fromYDelta y축의 시작 위치
    toYDelta y축의 마지막 위치
    duration 애니메이션 작동 시간
-->
<!--    <translate android:fromYDelta="100%"
        android:toYDelta="0"
        android:duration="3000"
        />-->

    <translate android:fromYDelta="0%"
        android:toYDelta="100%"
        android:duration="3000"
        android:repeatCount="1"
        android:repeatMode="reverse"
        />


</set>

 

 

회전

rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<!--rotate.xml-->
<rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="3000"
    />
<!--

fromDegree 시작 각도
toDegrees 끝 각도
pivotX 회전축의 x좌표
pivotY 회전축의 y좌표
duration 애니메이션 작동 시간

-->



</set>

 

 

 

투명도

 

alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<!--alpha.xml-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="5000"
        android:repeatCount="2"
        android:repeatMode="reverse"
        />
<!--
0.0 완전투명 ~ 1.0 완전불투명
fromAlpha 투명도 처음 값
toAlpha  투명도 마지막 값
duration 애니메이션 작동 시간
repeatCount 반복 횟수
repeatMode 반복 옵션 reverse, restart

-->
</set>

 

 

크기조절

 

scale.xml
<?xml version="1.0" encoding="utf-8"?>
<!--scale.xml-->
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <scale
        android:fromXScale="1.0"
        android:toXScale="0.1"
        android:fromYScale="1.0"
        android:toYScale="0.1"
        android:pivotY="50%"
        android:pivotX="50%"
        android:duration="2000"
        />

<!--
    fromXScale x축의 시작 사이즈 toXScale x 축의 끝 사이즈
    fromYScale y축의 시작 사이즈 toYScale y축의 끝 사이즈 prvotX
    중심축(x좌표) pivotY 중심축(y좌표)
    -->


</set>



 

혼합

 

set.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">


    <rotate android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="3000"
        />

    <scale
        android:fromXScale="1.0"
        android:toXScale="0.1"
        android:fromYScale="1.0"
        android:toYScale="0.1"
        android:pivotY="50%"
        android:pivotX="50%"
        android:duration="2000"
        android:repeatCount="1"
        android:repeatMode="reverse"
        />

    <translate android:fromYDelta="0%"
        android:toYDelta="100%"
        android:duration="3000"
        android:repeatCount="1"
        android:repeatMode="reverse"
        />

    <alpha
        android:fromAlpha="1.0"
        android:toAlpha="0.0"
        android:duration="5000"
        android:repeatCount="2"
        android:repeatMode="reverse"
        />


</set>







 

 

 

 

 

 

 

about author

PHRASE

Level 60  머나먼나라

자기의 결점만을 걱정하고 있는 사람은, 인간이 갖는 결점을 깨닫지 못한다. -탈무드

댓글 ( 4)

댓글 남기기

작성