path2.0的動態菜單確實很炫,但是在網上沒找的android版本,因而就本身實現了一下。感受效果還能夠,就分享出來讓你們一塊兒來改進。最終但願能實現iPhone上那種效果。 android
見源碼: app
Java代碼 composer
1 packagecom.path.demo; ide
2 this
3 importandroid.app.Activity; spa
4 importandroid.graphics.Bitmap; code
5 importandroid.graphics.BitmapFactory; xml
6 importandroid.graphics.Matrix; utf-8
7 importandroid.os.Bundle; get
8 importandroid.view.View;
9 importandroid.view.View.OnClickListener;
10 importandroid.view.animation.Animation;
11 importandroid.view.animation.LinearInterpolator;
12 importandroid.view.animation.RotateAnimation;
13 importandroid.view.animation.TranslateAnimation;
14 importandroid.view.animation.Animation.AnimationListener;
15 importandroid.widget.ImageView;
16 publicclassTestPathActivityextendsActivityimplementsOnClickListener{
17
18 privateImageViewivComposer;
19 privateRotateAnimationclockwiseAm;
20 privateRotateAnimationanticlockwiseAm;
21
22 privateImageViewivCamera;
23 privateTranslateAnimationcameraOutTA;//相機
24 privateTranslateAnimationcameraInTA;
25
26 privateImageViewivWith;
27 privateTranslateAnimationwithOutTA;
28 privateTranslateAnimationwithInTA;
29
30 privateImageViewivPlace;
31 privateTranslateAnimationplaceOutTA;
32 privateTranslateAnimationplaceInTA;
33
34 privateImageViewivMusic;
35 privateTranslateAnimationmusicOutTA;
36 privateTranslateAnimationmusicInTA;
37
38 privateImageViewivThought;
39 privateTranslateAnimationthoughtOutTA;
40 privateTranslateAnimationthoughtInTA;
41
42 privateImageViewivSleep;
43 privateTranslateAnimationsleepOutTA;
44 privateTranslateAnimationsleepInTA;
45
46
47
48 @Override
49 publicvoidonCreate(BundlesavedInstanceState){
50 super.onCreate(savedInstanceState);
51 setContentView(R.layout.main);
52 findView();
53 }
54
55 privatevoidfindView(){
56 ivComposer=(ImageView)this.findViewById(R.id.ivComposer);
57 ivComposer.setOnClickListener(this);
58 //am=newRotateAnimation(0,360,13,13);
59 clockwiseAm=newRotateAnimation(0,+360,
60 Animation.RELATIVE_TO_SELF,0.5f,
61 Animation.RELATIVE_TO_SELF,0.5f);
62 clockwiseAm.setDuration(300);
63 LinearInterpolatorlin=newLinearInterpolator();
64 clockwiseAm.setInterpolator(lin);
65 clockwiseAm.setAnimationListener(clockwiseAmListener);
66
67 anticlockwiseAm=newRotateAnimation(0,-360,
68 Animation.RELATIVE_TO_SELF,0.5f,
69 Animation.RELATIVE_TO_SELF,0.5f);
70 anticlockwiseAm.setDuration(300);
71 anticlockwiseAm.setInterpolator(lin);
72 anticlockwiseAm.setAnimationListener(anticlockwiseAmListener);
73
74 ivCamera=(ImageView)this.findViewById(R.id.ivCamera);
75 ivCamera.setOnClickListener(this);
76 cameraOutTA=newTranslateAnimation(Animation.ABSOLUTE,-5.0f,Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,240.0f,Animation.ABSOLUTE,10.0f);
77 cameraOutTA.setDuration(200);
78 cameraInTA=newTranslateAnimation(Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,-5.0f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,240.0f);
79 cameraInTA.setDuration(200);
80
81 ivWith=(ImageView)this.findViewById(R.id.ivWith);
82 ivWith.setOnClickListener(this);
83 withOutTA=newTranslateAnimation(Animation.ABSOLUTE,-75f,Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,225.0f,Animation.ABSOLUTE,10.0f);
84 withOutTA.setDuration(200);
85 withInTA=newTranslateAnimation(Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,-75f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,225.0f);
86 withInTA.setDuration(200);
87
88 ivPlace=(ImageView)this.findViewById(R.id.ivPlace);
89 ivPlace.setOnClickListener(this);
90 placeOutTA=newTranslateAnimation(Animation.ABSOLUTE,-135f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,190f,Animation.ABSOLUTE,10.0f);
91 placeOutTA.setDuration(200);
92 placeInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-135f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,190f);
93 placeInTA.setDuration(200);
94
95 ivMusic=(ImageView)this.findViewById(R.id.ivMusic);
96 ivMusic.setOnClickListener(this);
97 musicOutTA=newTranslateAnimation(Animation.ABSOLUTE,-175f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,130f,Animation.ABSOLUTE,10.0f);
98 musicOutTA.setDuration(200);
99 musicInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-175f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,130f);
100 musicInTA.setDuration(200);
101
102 ivThought=(ImageView)this.findViewById(R.id.ivThought);
103 ivThought.setOnClickListener(this);
104 thoughtOutTA=newTranslateAnimation(Animation.ABSOLUTE,-205f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,70f,Animation.ABSOLUTE,10.0f);
105 thoughtOutTA.setDuration(200);
106 thoughtInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-205f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,70f);
107 thoughtInTA.setDuration(200);
108
109 ivSleep=(ImageView)this.findViewById(R.id.ivSleep);
110 ivSleep.setOnClickListener(this);
111 sleepOutTA=newTranslateAnimation(Animation.ABSOLUTE,-215f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,5f,Animation.ABSOLUTE,10.0f);
112 sleepOutTA.setDuration(200);
113 sleepInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-215f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,5f);
114 sleepInTA.setDuration(200);
115 }
116
117 @Override
118 publicvoidonClick(Viewv){
119 switch(v.getId()){
120 caseR.id.ivComposer:
121 if(isClockwise){
122 ivComposer.startAnimation(clockwiseAm);
123 ivCamera.startAnimation(cameraOutTA);
124 ivCamera.setVisibility(View.VISIBLE);
125
126 withOutTA.setStartOffset(20);
127 ivWith.startAnimation(withOutTA);
128 ivWith.setVisibility(View.VISIBLE);
129
130 placeOutTA.setStartOffset(40);
131 ivPlace.startAnimation(placeOutTA);
132 ivPlace.setVisibility(View.VISIBLE);
133
134 musicOutTA.setStartOffset(60);
135 ivMusic.startAnimation(musicOutTA);
136 ivMusic.setVisibility(View.VISIBLE);
137
138 thoughtOutTA.setStartOffset(80);
139 ivThought.startAnimation(thoughtOutTA);
140 ivThought.setVisibility(View.VISIBLE);
141
142 sleepOutTA.setStartOffset(100);
143 ivSleep.startAnimation(sleepOutTA);
144 ivSleep.setVisibility(View.VISIBLE);
145 }else{
146 ivComposer.startAnimation(anticlockwiseAm);
147
148 ivSleep.startAnimation(sleepInTA);
149 ivSleep.setVisibility(View.GONE);
150
151 thoughtInTA.setStartOffset(20);
152 ivThought.startAnimation(thoughtInTA);
153 ivThought.setVisibility(View.GONE);
154
155 musicInTA.setStartOffset(40);
156 ivMusic.startAnimation(musicInTA);
157 ivMusic.setVisibility(View.GONE);
158
159 placeInTA.setStartOffset(60);
160 ivPlace.startAnimation(placeInTA);
161 ivPlace.setVisibility(View.GONE);
162
163 withInTA.setStartOffset(80);
164 ivWith.startAnimation(withInTA);
165 ivWith.setVisibility(View.GONE);
166
167 cameraInTA.setStartOffset(100);
168 ivCamera.startAnimation(cameraInTA);
169 ivCamera.setVisibility(View.GONE);
170 }
171 break;
172 caseR.id.ivCamera:
173
174 break;
175 caseR.id.ivWith:
176
177 break;
178 caseR.id.ivPlace:
179
180 break;
181 caseR.id.ivThought:
182
183 break;
184 caseR.id.ivMusic:
185
186 break;
187 caseR.id.ivSleep:
188
189 break;
190 }
191 }
192 privatebooleanisClockwise=true;
193 privateAnimationListenerclockwiseAmListener=newAnimationListener(){
194 publicvoidonAnimationEnd(Animationarg0){
195 Matrixmatrix=newMatrix();
196 matrix.setRotate(45);
197 Bitmapsource=BitmapFactory.decodeResource(TestPathActivity.this.getResources(),R.drawable.composer_icn_plus);
198 BitmapresizedBitmap=Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight(),matrix,true);
199 ivComposer.setImageBitmap(resizedBitmap);
200 if(source!=null&&!source.isRecycled())
201 source.recycle();
202 isClockwise=false;
203 }
204 publicvoidonAnimationRepeat(Animationanimation){
205 }
206 publicvoidonAnimationStart(Animationanimation){
207 }
208 };
209 privateAnimationListeneranticlockwiseAmListener=newAnimationListener(){
210 publicvoidonAnimationEnd(Animationarg0){
211 Bitmapsource=BitmapFactory.decodeResource(TestPathActivity.this.getResources(),R.drawable.composer_icn_plus);
212 ivComposer.setImageBitmap(source);
213 isClockwise=true;
214 }
215 publicvoidonAnimationRepeat(Animationanimation){
216 }
217 publicvoidonAnimationStart(Animationanimation){
218 }
219 };
220 }
221 -------------------------------------------------------------------------
222 <?xmlversion="1.0"encoding="utf-8"?>
223 <manifestxmlns:android="http://schemas.android.com/apk/res/android"
224 package="com.path.demo"
225 android:versionCode="1"
226 android:versionName="1.0">
227
228 <uses-sdkandroid:minSdkVersion="8"/>
229
230 <application
231 android:icon="@drawable/ic_launcher"
232 android:label="@string/app_name">
233 <activity
234 android:label="@string/app_name"
235 android:name=".TestPathActivity">
236 <intent-filter>
237 <actionandroid:name="android.intent.action.MAIN"/>
238
239 <categoryandroid:name="android.intent.category.LAUNCHER"/>
240 </intent-filter>
241 </activity>
242 </application>
243
244 </manifest>