path2.0的动态菜单确实很炫,可是在网上没找的android版本,于是就自己实现了一下。感觉效果还可以,就分享出来让大家一起来改进。最终希望能实现iPhone上那种效果。


见源码:

Java代码

1packagecom.path.demo;

2

3importandroid.app.Activity;

4importandroid.graphics.Bitmap;

5importandroid.graphics.BitmapFactory;

6importandroid.graphics.Matrix;

7importandroid.os.Bundle;

8importandroid.view.View;

9importandroid.view.View.OnClickListener;

10importandroid.view.animation.Animation;

11importandroid.view.animation.LinearInterpolator;

12importandroid.view.animation.RotateAnimation;

13importandroid.view.animation.TranslateAnimation;

14importandroid.view.animation.Animation.AnimationListener;

15importandroid.widget.ImageView;

16publicclassTestPathActivityextendsActivityimplementsOnClickListener{

17

18privateImageViewivComposer;

19privateRotateAnimationclockwiseAm;

20privateRotateAnimationanticlockwiseAm;

21

22privateImageViewivCamera;

23privateTranslateAnimationcameraOutTA;//相机

24privateTranslateAnimationcameraInTA;

25

26privateImageViewivWith;

27privateTranslateAnimationwithOutTA;

28privateTranslateAnimationwithInTA;

29

30privateImageViewivPlace;

31privateTranslateAnimationplaceOutTA;

32privateTranslateAnimationplaceInTA;

33

34privateImageViewivMusic;

35privateTranslateAnimationmusicOutTA;

36privateTranslateAnimationmusicInTA;

37

38privateImageViewivThought;

39privateTranslateAnimationthoughtOutTA;

40privateTranslateAnimationthoughtInTA;

41

42privateImageViewivSleep;

43privateTranslateAnimationsleepOutTA;

44privateTranslateAnimationsleepInTA;

45

46

47

48@Override

49publicvoidonCreate(BundlesavedInstanceState){

50super.onCreate(savedInstanceState);

51setContentView(R.layout.main);

52findView();

53}

54

55privatevoidfindView(){

56ivComposer=(ImageView)this.findViewById(R.id.ivComposer);

57ivComposer.setOnClickListener(this);

58//am=newRotateAnimation(0,360,13,13);

59clockwiseAm=newRotateAnimation(0,+360,

60Animation.RELATIVE_TO_SELF,0.5f,

61Animation.RELATIVE_TO_SELF,0.5f);

62clockwiseAm.setDuration(300);

63LinearInterpolatorlin=newLinearInterpolator();

64clockwiseAm.setInterpolator(lin);

65clockwiseAm.setAnimationListener(clockwiseAmListener);

66

67anticlockwiseAm=newRotateAnimation(0,-360,

68Animation.RELATIVE_TO_SELF,0.5f,

69Animation.RELATIVE_TO_SELF,0.5f);

70anticlockwiseAm.setDuration(300);

71anticlockwiseAm.setInterpolator(lin);

72anticlockwiseAm.setAnimationListener(anticlockwiseAmListener);

73

74ivCamera=(ImageView)this.findViewById(R.id.ivCamera);

75ivCamera.setOnClickListener(this);

76cameraOutTA=newTranslateAnimation(Animation.ABSOLUTE,-5.0f,Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,240.0f,Animation.ABSOLUTE,10.0f);

77cameraOutTA.setDuration(200);

78cameraInTA=newTranslateAnimation(Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,-5.0f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,240.0f);

79cameraInTA.setDuration(200);

80

81ivWith=(ImageView)this.findViewById(R.id.ivWith);

82ivWith.setOnClickListener(this);

83withOutTA=newTranslateAnimation(Animation.ABSOLUTE,-75f,Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,225.0f,Animation.ABSOLUTE,10.0f);

84withOutTA.setDuration(200);

85withInTA=newTranslateAnimation(Animation.ABSOLUTE,0.0f,Animation.ABSOLUTE,-75f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,225.0f);

86withInTA.setDuration(200);

87

88ivPlace=(ImageView)this.findViewById(R.id.ivPlace);

89ivPlace.setOnClickListener(this);

90placeOutTA=newTranslateAnimation(Animation.ABSOLUTE,-135f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,190f,Animation.ABSOLUTE,10.0f);

91placeOutTA.setDuration(200);

92placeInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-135f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,190f);

93placeInTA.setDuration(200);

94

95ivMusic=(ImageView)this.findViewById(R.id.ivMusic);

96ivMusic.setOnClickListener(this);

97musicOutTA=newTranslateAnimation(Animation.ABSOLUTE,-175f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,130f,Animation.ABSOLUTE,10.0f);

98musicOutTA.setDuration(200);

99musicInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-175f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,130f);

100musicInTA.setDuration(200);

101

102ivThought=(ImageView)this.findViewById(R.id.ivThought);

103ivThought.setOnClickListener(this);

104thoughtOutTA=newTranslateAnimation(Animation.ABSOLUTE,-205f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,70f,Animation.ABSOLUTE,10.0f);

105thoughtOutTA.setDuration(200);

106thoughtInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-205f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,70f);

107thoughtInTA.setDuration(200);

108

109ivSleep=(ImageView)this.findViewById(R.id.ivSleep);

110ivSleep.setOnClickListener(this);

111sleepOutTA=newTranslateAnimation(Animation.ABSOLUTE,-215f,Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,5f,Animation.ABSOLUTE,10.0f);

112sleepOutTA.setDuration(200);

113sleepInTA=newTranslateAnimation(Animation.ABSOLUTE,-10.0f,Animation.ABSOLUTE,-215f,Animation.ABSOLUTE,10.0f,Animation.ABSOLUTE,5f);

114sleepInTA.setDuration(200);

115}

116

117@Override

118publicvoidonClick(Viewv){

119switch(v.getId()){

120caseR.id.ivComposer:

121if(isClockwise){

122ivComposer.startAnimation(clockwiseAm);

123ivCamera.startAnimation(cameraOutTA);

124ivCamera.setVisibility(View.VISIBLE);

125

126withOutTA.setStartOffset(20);

127ivWith.startAnimation(withOutTA);

128ivWith.setVisibility(View.VISIBLE);

129

130placeOutTA.setStartOffset(40);

131ivPlace.startAnimation(placeOutTA);

132ivPlace.setVisibility(View.VISIBLE);

133

134musicOutTA.setStartOffset(60);

135ivMusic.startAnimation(musicOutTA);

136ivMusic.setVisibility(View.VISIBLE);

137

138thoughtOutTA.setStartOffset(80);

139ivThought.startAnimation(thoughtOutTA);

140ivThought.setVisibility(View.VISIBLE);

141

142sleepOutTA.setStartOffset(100);

143ivSleep.startAnimation(sleepOutTA);

144ivSleep.setVisibility(View.VISIBLE);

145}else{

146ivComposer.startAnimation(anticlockwiseAm);

147

148ivSleep.startAnimation(sleepInTA);

149ivSleep.setVisibility(View.GONE);

150

151thoughtInTA.setStartOffset(20);

152ivThought.startAnimation(thoughtInTA);

153ivThought.setVisibility(View.GONE);

154

155musicInTA.setStartOffset(40);

156ivMusic.startAnimation(musicInTA);

157ivMusic.setVisibility(View.GONE);

158

159placeInTA.setStartOffset(60);

160ivPlace.startAnimation(placeInTA);

161ivPlace.setVisibility(View.GONE);

162

163withInTA.setStartOffset(80);

164ivWith.startAnimation(withInTA);

165ivWith.setVisibility(View.GONE);

166

167cameraInTA.setStartOffset(100);

168ivCamera.startAnimation(cameraInTA);

169ivCamera.setVisibility(View.GONE);

170}

171break;

172caseR.id.ivCamera:

173

174break;

175caseR.id.ivWith:

176

177break;

178caseR.id.ivPlace:

179

180break;

181caseR.id.ivThought:

182

183break;

184caseR.id.ivMusic:

185

186break;

187caseR.id.ivSleep:

188

189break;

190}

191}

192privatebooleanisClockwise=true;

193privateAnimationListenerclockwiseAmListener=newAnimationListener(){

194publicvoidonAnimationEnd(Animationarg0){

195Matrixmatrix=newMatrix();

196matrix.setRotate(45);

197Bitmapsource=BitmapFactory.decodeResource(TestPathActivity.this.getResources(),R.drawable.composer_icn_plus);

198BitmapresizedBitmap=Bitmap.createBitmap(source,0,0,source.getWidth(),source.getHeight(),matrix,true);

199ivComposer.setImageBitmap(resizedBitmap);

200if(source!=null&&!source.isRecycled())

201source.recycle();

202isClockwise=false;

203}

204publicvoidonAnimationRepeat(Animationanimation){

205}

206publicvoidonAnimationStart(Animationanimation){

207}

208};

209privateAnimationListeneranticlockwiseAmListener=newAnimationListener(){

210publicvoidonAnimationEnd(Animationarg0){

211Bitmapsource=BitmapFactory.decodeResource(TestPathActivity.this.getResources(),R.drawable.composer_icn_plus);

212ivComposer.setImageBitmap(source);

213isClockwise=true;

214}

215publicvoidonAnimationRepeat(Animationanimation){

216}

217publicvoidonAnimationStart(Animationanimation){

218}

219};

220}

221-------------------------------------------------------------------------

222<?xmlversion="1.0"encoding="utf-8"?>

223<manifestxmlns:android="http://schemas.android.com/apk/res/android"

224package="com.path.demo"

225android:versionCode="1"

226android:versionName="1.0">

227

228<uses-sdkandroid:minSdkVersion="8"/>

229

230<application

231android:icon="@drawable/ic_launcher"

232android:label="@string/app_name">

233<activity

234android:label="@string/app_name"

235android: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>


更多相关文章

  1. Android实现简单水波纹效果
  2. Android下用gdb进行系统级源码调试
  3. Android(安卓)仿ios下拉放大图片过度拉伸效果的最佳方案
  4. android图片上传服务器
  5. LinearLayout的layout_weight的使用
  6. Adapter 优化图片复用,导致界面图片出现闪烁效果
  7. ANDROID L——RecyclerView,CardView导入和使用
  8. 【Android(安卓)界面效果43】Android(安卓)LayoutInflater的infl
  9. Android深入浅出系列课程--Lesson11 Android.Framework源码下载

随机推荐

  1. Android(安卓)如何使用internal 和 hidde
  2. Cocos2dx setup Eclipse environment for
  3. Android四种布局
  4. Android(安卓)FTP客户端使用,快速上传文件
  5. Android(安卓)MediaProvider详解(基础篇)
  6. Android(安卓)远程监控摄像头 移动端+PC
  7. Intent在Android中的几种用法
  8. android:clipChildren属性的分析——是否
  9. Android(安卓)drawableleft如何设置图片
  10. ArcGIS Runtime SDK for Android(安卓)10