7
7
import android .view .animation .AnticipateInterpolator ;
8
8
import android .view .animation .OvershootInterpolator ;
9
9
import android .view .animation .RotateAnimation ;
10
+ import android .view .animation .ScaleAnimation ;
10
11
import android .view .animation .TranslateAnimation ;
11
12
import android .widget .ImageButton ;
12
13
13
- public class PathAnimations {
14
-
15
- private static int xOffset = 15 ;
16
- private static int yOffset = -13 ;
14
+ public class PathAnimations
15
+ {
17
16
18
- public static void initOffset (Context context ){//由布局文件
19
- xOffset = (int ) (10.667 *context .getResources ().getDisplayMetrics ().density );
20
- yOffset = -(int ) (8.667 *context .getResources ().getDisplayMetrics ().density );
17
+ private static int xOffset = 16 ;
18
+ private static int yOffset = -13 ;
19
+
20
+ public static Animation getScaleAnimation (float fromX , float toX ,
21
+ float fromY , float toY , int durationMillis )
22
+ {
23
+ ScaleAnimation scale = new ScaleAnimation (fromX , toX , fromY , toY ,
24
+ Animation .RELATIVE_TO_SELF , 0.5f , Animation .RELATIVE_TO_SELF ,
25
+ 0.5f );
26
+ scale .setDuration (durationMillis );
27
+ scale .setFillAfter (true );
28
+ return scale ;
29
+ }
30
+
31
+ public static void initOffset (Context context )
32
+ {
33
+ // 由布局文件
34
+ xOffset = (int ) (10.667 * context .getResources ().getDisplayMetrics ().density );
35
+ yOffset = -(int ) (8.667 * context .getResources ().getDisplayMetrics ().density );
21
36
}
22
-
23
- public static Animation getRotateAnimation (float fromDegrees ,float toDegrees ,int durationMillis ){
37
+
38
+ public static Animation getRotateAnimation (float fromDegrees ,
39
+ float toDegrees , int durationMillis )
40
+ {
24
41
RotateAnimation rotate = new RotateAnimation (fromDegrees , toDegrees ,
25
- Animation .RELATIVE_TO_SELF , 0.5f , Animation .RELATIVE_TO_SELF , 0.5f );
42
+ Animation .RELATIVE_TO_SELF , 0.5f , Animation .RELATIVE_TO_SELF ,
43
+ 0.5f );
26
44
rotate .setDuration (durationMillis );
27
45
rotate .setFillAfter (true );
28
46
return rotate ;
29
47
}
30
48
31
- public static void startAnimationsIn (ViewGroup viewgroup ,int durationMillis ) {
32
- for (int i = 0 ; i < viewgroup .getChildCount (); i ++) {
33
- ImageButton inoutimagebutton = (ImageButton ) viewgroup
34
- .getChildAt (i );
35
- inoutimagebutton .setVisibility (0 );
36
- MarginLayoutParams mlp = (MarginLayoutParams ) inoutimagebutton .getLayoutParams ();
37
- Animation animation = new TranslateAnimation (mlp .rightMargin -xOffset ,0F ,yOffset + mlp .bottomMargin , 0F );
38
-
39
- animation .setFillAfter (true );animation .setDuration (durationMillis );
40
- animation .setStartOffset ((i * 100 )
41
- / (-1 + viewgroup .getChildCount ()));
42
- animation .setInterpolator (new OvershootInterpolator (2F ));
43
- inoutimagebutton .startAnimation (animation );
44
-
49
+ public static void startAnimationsIn (ViewGroup viewgroup , int durationMillis )
50
+ {
51
+ for (int i = 0 ; i < viewgroup .getChildCount (); i ++)
52
+ {
53
+ ImageButton inoutimagebutton = (ImageButton ) viewgroup
54
+ .getChildAt (i );
55
+ inoutimagebutton .setVisibility (0 );
56
+ inoutimagebutton .setFocusable (true );
57
+ inoutimagebutton .setClickable (true );
58
+ MarginLayoutParams mlp = (MarginLayoutParams ) inoutimagebutton
59
+ .getLayoutParams ();
60
+ Animation animation = new TranslateAnimation (Animation .ABSOLUTE ,
61
+ mlp .rightMargin - xOffset , Animation .RELATIVE_TO_SELF , 0F ,
62
+ Animation .ABSOLUTE , yOffset + mlp .bottomMargin ,
63
+ Animation .RELATIVE_TO_SELF , 0F );
64
+
65
+ animation .setFillAfter (true );
66
+ animation .setDuration (durationMillis );
67
+ animation .setStartOffset ((i * 100 )
68
+ / (-1 + viewgroup .getChildCount ()));
69
+ animation .setInterpolator (new OvershootInterpolator (2F ));
70
+ inoutimagebutton .startAnimation (animation );
71
+
45
72
}
46
73
}
47
- public static void startAnimationsOut (ViewGroup viewgroup ,int durationMillis ) {
48
- for (int i = 0 ; i < viewgroup .getChildCount (); i ++) {
49
- final ImageButton inoutimagebutton = (ImageButton ) viewgroup
50
- .getChildAt (i );
51
- MarginLayoutParams mlp = (MarginLayoutParams ) inoutimagebutton .getLayoutParams ();
52
- Animation animation = new TranslateAnimation (0F ,mlp .rightMargin -xOffset , 0F ,yOffset + mlp .bottomMargin );
53
-
54
- animation .setFillAfter (true );animation .setDuration (durationMillis );
55
- animation .setStartOffset (((viewgroup .getChildCount ()-i ) * 100 )
56
- / (-1 + viewgroup .getChildCount ()));//顺序倒一下比较舒服
57
- animation .setInterpolator (new AnticipateInterpolator (2F ));
58
- animation .setAnimationListener (new Animation .AnimationListener () {
59
- @ Override
60
- public void onAnimationStart (Animation arg0 ) {}
61
- @ Override
62
- public void onAnimationRepeat (Animation arg0 ) {}
63
- @ Override
64
- public void onAnimationEnd (Animation arg0 ) {
65
- // TODO Auto-generated method stub
66
- inoutimagebutton .setVisibility (8 );
67
- }
68
- });
69
- inoutimagebutton .startAnimation (animation );
70
- }
71
-
74
+
75
+ public static void startAnimationsOut (ViewGroup viewgroup ,
76
+ int durationMillis )
77
+ {
78
+ for (int i = 0 ; i < viewgroup .getChildCount (); i ++)
79
+ {
80
+ final ImageButton inoutimagebutton = (ImageButton ) viewgroup
81
+ .getChildAt (i );
82
+ MarginLayoutParams mlp = (MarginLayoutParams ) inoutimagebutton
83
+ .getLayoutParams ();
84
+ Animation animation = new TranslateAnimation (0F , mlp .rightMargin
85
+ - xOffset , 0F , yOffset + mlp .bottomMargin );
86
+
87
+ animation .setFillAfter (true );
88
+ animation .setDuration (durationMillis );
89
+ animation .setStartOffset (((viewgroup .getChildCount () - i ) * 100 )
90
+ / (-1 + viewgroup .getChildCount ()));// 顺序倒一下比较舒服
91
+ animation .setInterpolator (new AnticipateInterpolator (2F ));
92
+ animation .setAnimationListener (new Animation .AnimationListener ()
93
+ {
94
+ @ Override
95
+ public void onAnimationStart (Animation arg0 )
96
+ {
97
+ }
98
+
99
+ @ Override
100
+ public void onAnimationRepeat (Animation arg0 )
101
+ {
102
+ }
103
+
104
+ @ Override
105
+ public void onAnimationEnd (Animation arg0 )
106
+ {
107
+ // TODO Auto-generated method stub
108
+ inoutimagebutton .setVisibility (8 );
109
+ inoutimagebutton .setFocusable (false );
110
+ inoutimagebutton .setClickable (false );
111
+ }
112
+ });
113
+ inoutimagebutton .startAnimation (animation );
114
+ }
115
+
72
116
}
73
117
74
-
75
118
}
0 commit comments