android版的path2.0菜单功能实现

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


见源码:

Java代码

1 packagecom.path.demo; 

3 importandroid.app.Activity; 

4 importandroid.graphics.Bitmap; 

5 importandroid.graphics.BitmapFactory; 

6 importandroid.graphics.Matrix; 

7 importandroid.os.Bundle; 

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>


转载于:https://my.oschina.net/microoh/blog/144060

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值