forked from D-clock/AndroidStudyCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimationActivity.java
More file actions
110 lines (85 loc) · 4.53 KB
/
AnimationActivity.java
File metadata and controls
110 lines (85 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.clock.study.activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import com.clock.study.R;
import com.clock.study.animation.SimpleCustomAnimation;
/**
* Android动画效果实现复习
*/
public class AnimationActivity extends AppCompatActivity implements View.OnClickListener {
private Button mBtnTranslate;
private Button mBtnScale;
private Button mBtnRotate;
private Button mBtnAlpha;
private Button mBtnSet;
private Button mBtnSimpleCustom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_android_anim);
mBtnTranslate = (Button) findViewById(R.id.btn_translate);
mBtnTranslate.setOnClickListener(this);
mBtnScale = (Button) findViewById(R.id.btn_scale);
mBtnScale.setOnClickListener(this);
mBtnRotate = (Button) findViewById(R.id.btn_rotate);
mBtnRotate.setOnClickListener(this);
mBtnAlpha = (Button) findViewById(R.id.btn_alpha);
mBtnAlpha.setOnClickListener(this);
mBtnSet = (Button) findViewById(R.id.btn_set);
mBtnSet.setOnClickListener(this);
mBtnSimpleCustom = (Button) findViewById(R.id.btn_simple_custom_anim);
mBtnSimpleCustom.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int viewId = v.getId();
if (viewId == R.id.btn_translate) {//偏移动画
//TranslateAnimation translateAnim = new TranslateAnimation(0, 500, 0, 500);
/*TranslateAnimation translateAnim = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 500, Animation.ABSOLUTE, 0,
Animation.ABSOLUTE, 500);*/
TranslateAnimation translateAnim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0,
Animation.RELATIVE_TO_PARENT, 1.0f);
translateAnim.setDuration(2000);
mBtnTranslate.startAnimation(translateAnim);
//translateAnim.setFillAfter(true);//保持动画效果
} else if (viewId == R.id.btn_scale) {//缩放动画
//ScaleAnimation scaleAnim = new ScaleAnimation(0.5f, 1, 0.5f, 1);
//ScaleAnimation scaleAnim = new ScaleAnimation(0.5f, 1, 0.5f, 1, 300, 300);
ScaleAnimation scaleAnim = new ScaleAnimation(0.5f, 1, 0.5f, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnim.setDuration(1000);
mBtnScale.startAnimation(scaleAnim);
} else if (viewId == R.id.btn_rotate) {//旋转动画
//RotateAnimation rotateAnim = new RotateAnimation(0, 360);
//RotateAnimation rotateAnim = new RotateAnimation(0, 360, 100, 100);
RotateAnimation rotateAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(2000);
mBtnRotate.startAnimation(rotateAnim);
} else if (viewId == R.id.btn_alpha) {//透明度动画
AlphaAnimation alphaAnim = new AlphaAnimation(0, 1);
alphaAnim.setDuration(2000);
mBtnAlpha.startAnimation(alphaAnim);
} else if (viewId == R.id.btn_set) {//动画合集
AnimationSet animSet = new AnimationSet(true);
animSet.setDuration(2000);
RotateAnimation rotateAnim = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animSet.addAnimation(rotateAnim);
animSet.addAnimation(scaleAnimation);
AlphaAnimation alphaAnim = new AlphaAnimation(0, 1);
animSet.addAnimation(alphaAnim);
mBtnSet.startAnimation(animSet);
} else if (viewId == R.id.btn_simple_custom_anim) {
SimpleCustomAnimation simpleCustomAnim = new SimpleCustomAnimation();//简单的自定义动画效果
simpleCustomAnim.setDuration(1000);
mBtnSimpleCustom.startAnimation(simpleCustomAnim);
}
}
}