首页 文章 精选 留言 我的

精选列表

搜索[数字经济],共10000篇文章
优秀的个人博客,低调大师

Android第四十期 - 动画数字三元归一

最近太忙,天天都下半夜,但是还是做出来一些成绩,这个效果以后大家需要的话可以改改,代码已经整理好,效果如下: 想想还是跟大家讲一下吧,这些还是有一些技巧的。 首先是字体部分,动态的变化会随着上下的滚动递增递减,效果如下: 首先是布局文件: 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 <?xmlversion= "1.0" encoding= "utf-8" ?> <com.yuan.mytmall.MagicScrollViewxmlns:android= "http://schemas.android.com/apk/res/android" android:id= "@+id/magic_scroll" android:layout_width= "match_parent" android:layout_height= "match_parent" android:background= "@color/white" android:scrollbars= "none" > <LinearLayout android:id= "@+id/container" android:layout_width= "match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <RelativeLayout android:id= "@+id/code_layout" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:background= "@color/cyan" android:orientation= "vertical" android:paddingBottom= "20dp" android:paddingTop= "20dp" > <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_alignParentLeft= "true" android:layout_marginLeft= "10dp" android:text= "当前账户:" android:textColor= "@color/white" android:textSize= "18sp" /> <FrameLayout android:layout_width= "120dp" android:layout_height= "120dp" android:layout_centerInParent= "true" > <com.geek.view.RoundImageViewByXfermode android:id= "@+id/patientmg_code_img3" android:layout_width= "100dp" android:layout_height= "100dp" android:layout_gravity= "center" android:contentDescription= "@null" android:padding= "7dp" android:src= "@drawable/white3" /> </FrameLayout> <FrameLayout android:layout_width= "120dp" android:layout_height= "120dp" android:layout_centerInParent= "true" > <com.geek.view.RoundImageViewByXfermode android:id= "@+id/patientmg_code_img2" android:layout_width= "100dp" android:layout_height= "100dp" android:layout_gravity= "center" android:contentDescription= "@null" android:padding= "7dp" android:src= "@drawable/white2" /> </FrameLayout> <FrameLayout android:layout_width= "120dp" android:layout_height= "120dp" android:layout_centerInParent= "true" > <com.geek.view.RoundImageViewByXfermode android:id= "@+id/patientmg_code_img1" android:layout_width= "100dp" android:layout_height= "100dp" android:layout_gravity= "center" android:contentDescription= "@null" android:padding= "7dp" android:src= "@drawable/white1" /> </FrameLayout> <FrameLayout android:layout_width= "120dp" android:layout_height= "120dp" android:layout_centerInParent= "true" > <com.geek.view.RoundImageViewByXfermode android:id= "@+id/patientmg_code_img" android:layout_width= "100dp" android:layout_height= "100dp" android:layout_gravity= "center" android:contentDescription= "@null" android:padding= "7dp" android:src= "@drawable/white0" /> </FrameLayout> <FrameLayout android:layout_width= "100dp" android:layout_height= "100dp" android:layout_centerInParent= "true" > <RelativeLayout android:id= "@+id/rllob" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_gravity= "center" > <com.yuan.mytmall.MagicTextView android:id= "@+id/tv_qian" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:gravity= "center" android:text= "0.0" android:textColor= "@color/oriange" android:textSize= "20sp" /> </RelativeLayout> <TextView android:id= "@+id/tv_nick3" android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:layout_below= "@+id/rllob" android:layout_gravity= "bottom" android:gravity= "center" android:paddingBottom= "5dp" android:text= "元" android:textColor= "@color/gray" android:textSize= "20sp" /> </FrameLayout> </RelativeLayout> <LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" android:background= "@color/oriange" android:orientation= "vertical" android:padding= "15dp" > <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:text= "昨日收益" android:textColor= "@color/white" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/income_money" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "15dp" android:text= "0.00" android:textColor= "@color/white" android:textSize= "60sp" /> </LinearLayout> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginLeft= "15dp" android:layout_marginTop= "20dp" android:text= "总金额(元)" android:textColor= "@color/gray" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/total_money" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginLeft= "15dp" android:layout_marginTop= "5dp" android:text= "0.00" android:textColor= "@color/oriange" android:textSize= "45sp" /> <LinearLayout android:id= "@+id/income_total_bar" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "20dp" android:background= "@color/light_gray" > <LinearLayout android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:orientation= "vertical" android:padding= "10dp" > <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "累计收益(元)" android:textColor= "@color/gray" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/income_total_txt" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginTop= "5dp" android:text= "0.0" android:textColor= "@color/black" android:textSize= "30sp" /> </LinearLayout> <LinearLayout android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:orientation= "vertical" android:padding= "10dp" > <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "七日年化收益率" android:textColor= "@color/gray" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/income_sevdays_txt" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginTop= "5dp" android:text= "0.00" android:textColor= "@color/black" android:textSize= "30sp" /> </LinearLayout> </LinearLayout> <LinearLayout android:id= "@+id/income_nearly_bar" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:background= "@color/light_gray" > <LinearLayout android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:orientation= "vertical" android:padding= "10dp" > <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "近一周收益(元)" android:textColor= "@color/gray" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/income_week_txt" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginTop= "5dp" android:text= "0.00" android:textColor= "@color/black" android:textSize= "30sp" /> </LinearLayout> <LinearLayout android:layout_width= "0dp" android:layout_height= "match_parent" android:layout_weight= "1" android:orientation= "vertical" android:padding= "10dp" > <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "近一月收益(元)" android:textColor= "@color/gray" android:textSize= "20sp" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/income_month_txt" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginTop= "5dp" android:text= "0.0" android:textColor= "@color/black" android:textSize= "30sp" /> </LinearLayout> </LinearLayout> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "15dp" android:gravity= "center" android:text= "南京市" android:textColor= "@color/oriange" android:textSize= "25sp" /> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "8dp" android:gravity= "center" android:text= "你的收益战胜了" android:textColor= "@color/gray" /> <LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "15dp" android:gravity= "center" > <com.yuan.mytmall.MagicTextView android:id= "@+id/overperson_percent" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:text= "0.00" android:textColor= "@color/oriange" android:textSize= "35sp" /> <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginLeft= "2dp" android:text= "%" android:textColor= "@color/oriange" android:textSize= "35sp" /> </LinearLayout> <TextView android:layout_width= "match_parent" android:layout_height= "wrap_content" android:gravity= "center" android:text= "超过" android:textColor= "@color/gray" /> <com.yuan.mytmall.MagicTextView android:id= "@+id/overperson_count" android:layout_width= "match_parent" android:layout_height= "wrap_content" android:gravity= "center" android:text= "0" android:textColor= "@color/gray" android:textSize= "25sp" /> <LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "15dp" android:gravity= "center" > <com.yuan.mytmall.MagicTextView android:id= "@+id/overperson_percent2" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:gravity= "center" android:text= "0.00" android:textColor= "@color/oriange" android:textSize= "35sp" /> <TextView android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_marginLeft= "2dp" android:text= "%" android:textColor= "@color/oriange" android:textSize= "35sp" /> </LinearLayout> <LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" android:layout_marginTop= "15dp" android:gravity= "center" > </LinearLayout> </LinearLayout> </com.yuan.mytmall.MagicScrollView> 基类MagicScrollView: 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 package com.yuan.mytmall; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; public class MagicScrollView extends ScrollView{ private List<ScrollListener>mListeners= new ArrayList<MagicScrollView.ScrollListener>(); private int state= 0 ; public static final int UP= 1 ; public static final int DOWN= 2 ; public static final int STOP= 3 ; public interface ScrollListener{ void onScrollChanged( int state, int t); } public MagicScrollView(Contextcontext){ super (context); } public MagicScrollView(Contextcontext,AttributeSetset){ super (context,set); } public MagicScrollView(Contextcontext,AttributeSetset, int defStyle){ super (context,set,defStyle); } public void AddListener(ScrollListenerlistener){ if (mListeners== null ) mListeners= new ArrayList<MagicScrollView.ScrollListener>(); mListeners.add(listener); } @Override protected void onScrollChanged( int l, int t, int oldl, int oldt){ super .onScrollChanged(l,t,oldl,oldt); if (t>oldt){ state=UP; } else if (t<oldt){ state=DOWN; } else { state=STOP; } sendScroll(state,t); } public void sendScroll( int state, int scroll){ for (ScrollListenerlistener:mListeners){ listener.onScrollChanged(state,scroll); } } } 文字的基类MagicTextView: 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 package com.yuan.mytmall; import java.math.BigDecimal; import java.text.DecimalFormat; import android.content.Context; import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.widget.TextView; import com.yuan.mytmall.MagicScrollView.ScrollListener; public class MagicTextView extends TextView implements ScrollListener{ //view自身高度 private int mHeight; //view距离scrollView最顶端高度 private int locHeight; //递减/递增的变量值 private double mRate; //view设置的值 private double mValue; //当前显示的值 private double mCurValue; //当前变化后最终状态的目标值 private double mGalValue; //控制加减法 private int rate= 1 ; //当前变化状态(增/减/不变) private int mState= 0 ; private boolean refreshing; private static final int REFRESH= 1 ; private static final int SCROLL= 2 ; //偏移量主要用来进行校正距离。 private static final int OFFSET= 20 ; DecimalFormatfnum= new DecimalFormat( "0.00" ); private HandlermHandler= new Handler(){ public void handleMessage(android.os.Messagemsg){ switch (msg.what){ case REFRESH: if (rate*mCurValue<mGalValue){ refreshing= true ; setText(fnum.format(mCurValue)); mCurValue+=mRate*rate; mHandler.sendEmptyMessageDelayed(REFRESH, 50 ); } else { refreshing= false ; setText(fnum.format(mGalValue)); } break ; case SCROLL: doScroll(msg.arg1,msg.arg2); break ; default : break ; } }; }; public MagicTextView(Contextcontext){ super (context); } public MagicTextView(Contextcontext,AttributeSetset){ super (context,set); } public MagicTextView(Contextcontext,AttributeSetset, int defStyle){ super (context,set,defStyle); } public void setLocHeight( int height){ locHeight=height; } public void setValue( double value){ mCurValue= 0.00 ; mGalValue=isShown()?value: 0 ; mValue=value; mRate=( double )(mValue/ 20.00 ); BigDecimalb= new BigDecimal(mRate); mRate=b.setScale( 2 ,BigDecimal.ROUND_HALF_UP).doubleValue(); } @Override public void onScrollChanged( int state, int scroll){ Messagemsg=mHandler.obtainMessage(); msg.what=SCROLL; msg.arg1=state; msg.arg2=scroll; mHandler.sendMessage(msg); } private void doScroll( int state, int scroll){ if (mState==state&&refreshing) return ; mState=state; if (doMinus(scroll)){ rate=- 1 ; mGalValue= 0 ; } else if (doPlus(scroll)){ rate= 1 ; mGalValue=mValue; } mHandler.sendEmptyMessage(REFRESH); } private boolean doPlus( int scroll){ if (isShown()&&(scroll+PayActivity.mWinheight>locHeight+OFFSET) &&(mState==MagicScrollView.UP)) return true ; if (isShown()&&(scroll<locHeight)&&mState==MagicScrollView.DOWN) return true ; return false ; } private boolean doMinus( int scroll){ if (isShown()&&(scroll>locHeight)&&(mState==MagicScrollView.UP)) return true ; if (isShown()&&(scroll+PayActivity.mWinheight-mHeight<locHeight-OFFSET) &&(mState==MagicScrollView.DOWN)) return true ; return false ; } @Override protected void onMeasure( int widthMeasureSpec, int heightMeasureSpec){ super .onMeasure(widthMeasureSpec,heightMeasureSpec); //执行完onMeasure后即可获得view的宽度 mHeight=getMeasuredHeight(); } } 最后是Activity: 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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 package com.yuan.mytmall; import android.app.Activity; import android.content.res.Configuration; import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.DecelerateInterpolator; import android.view.animation.LinearInterpolator; import android.widget.ImageView; import android.widget.LinearLayout; public class PayActivity extends Activity{ private MagicTextViewtv_qian; private MagicScrollViewmScrollView; private MagicTextViewmIncomeTxt; private MagicTextViewmTotalMoneyTxt; private MagicTextViewmIncTotalTxt; private MagicTextViewmIncSevTxt; private MagicTextViewmIncWeekTxt; private MagicTextViewmIncMonTxt; private MagicTextViewmOverPerTxt; private MagicTextViewmOverPerTxt2; private MagicTextViewmOverCountTxt; private LinearLayoutmContainer; public static int mWinheight; int []location= new int [ 2 ]; private ImageViewinfoOperatingIV1,infoOperatingIV2,infoOperatingIV3; private AnimationoperatingAnim1; private AnimationoperatingAnim2; private AnimationoperatingAnim3; public void onConfigurationChanged(ConfigurationnewConfig){ super .onConfigurationChanged(newConfig); if (operatingAnim1!= null &&infoOperatingIV1!= null &&operatingAnim1.hasStarted()){ infoOperatingIV1.clearAnimation(); infoOperatingIV1.startAnimation(operatingAnim1); } if (operatingAnim2!= null &&infoOperatingIV2!= null &&operatingAnim2.hasStarted()){ infoOperatingIV2.clearAnimation(); infoOperatingIV2.startAnimation(operatingAnim2); } if (operatingAnim3!= null &&infoOperatingIV3!= null &&operatingAnim3.hasStarted()){ infoOperatingIV3.clearAnimation(); infoOperatingIV3.startAnimation(operatingAnim3); } } private HandlermHandler= new Handler(){ public void handleMessage(android.os.Messagemsg){ int height=mContainer.getMeasuredHeight(); Log.d( "heightis====>" , "" +height); onMeasureTxt(tv_qian); onMeasureTxt(mIncomeTxt); onMeasureTxt(mTotalMoneyTxt); onMeasureTxt(mIncTotalTxt); onMeasureTxt(mIncSevTxt); onMeasureTxt(mIncWeekTxt); onMeasureTxt(mIncMonTxt); onMeasureTxt(mOverPerTxt); onMeasureTxt(mOverPerTxt2); onMeasureTxt(mOverCountTxt); mScrollView.sendScroll(MagicScrollView.UP, 0 ); }; }; @Override protected void onCreate(BundlesavedInstanceState){ super .onCreate(savedInstanceState); setContentView(R.layout.magic_scroll_layout); Rectfram= new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(fram); mWinheight=fram.height(); Log.d( "winHeightis====>" , "" +mWinheight); mScrollView=(MagicScrollView)findViewById(R.id.magic_scroll); tv_qian=(MagicTextView)findViewById(R.id.tv_qian); mIncomeTxt=(MagicTextView)findViewById(R.id.income_money); mTotalMoneyTxt=(MagicTextView)findViewById(R.id.total_money); mIncTotalTxt=(MagicTextView)findViewById(R.id.income_total_txt); mIncSevTxt=(MagicTextView)findViewById(R.id.income_sevdays_txt); mIncWeekTxt=(MagicTextView)findViewById(R.id.income_week_txt); mIncMonTxt=(MagicTextView)findViewById(R.id.income_month_txt); mOverPerTxt=(MagicTextView)findViewById(R.id.overperson_percent); mOverPerTxt2=(MagicTextView)findViewById(R.id.overperson_percent2); mOverCountTxt=(MagicTextView)findViewById(R.id.overperson_count); mContainer=(LinearLayout)findViewById(R.id.container); tv_qian.setValue( 5360.00 ); mIncomeTxt.setValue( 3.30 ); mTotalMoneyTxt.setValue( 22800.56 ); mIncTotalTxt.setValue( 58.56 ); mIncSevTxt.setValue( 50.00 ); mIncWeekTxt.setValue( 20.00 ); mIncMonTxt.setValue( 40.20 ); mOverPerTxt.setValue( 88.88 ); mOverPerTxt2.setValue( 88.88 ); mOverCountTxt.setValue( 300000000 ); initListener(); mHandler.sendEmptyMessageDelayed( 0 , 1000 ); //三个圆的故事 infoOperatingIV1=(ImageView)findViewById(R.id.patientmg_code_img1); infoOperatingIV2=(ImageView)findViewById(R.id.patientmg_code_img2); infoOperatingIV3=(ImageView)findViewById(R.id.patientmg_code_img3); //动画部分 LinearInterpolatorlin= new LinearInterpolator(); //匀速运动 DecelerateInterpolatorlin2= new DecelerateInterpolator(); //减速运动 operatingAnim1=AnimationUtils.loadAnimation( this ,R.anim.tip1); operatingAnim1.setInterpolator(lin); if (operatingAnim1!= null ){ infoOperatingIV1.startAnimation(operatingAnim1); } operatingAnim2=AnimationUtils.loadAnimation( this ,R.anim.tip2); operatingAnim2.setInterpolator(lin); if (operatingAnim2!= null ){ infoOperatingIV2.startAnimation(operatingAnim2); } operatingAnim3=AnimationUtils.loadAnimation( this ,R.anim.tip3); operatingAnim3.setInterpolator(lin); if (operatingAnim3!= null ){ infoOperatingIV3.startAnimation(operatingAnim3); } } private void initListener(){ mScrollView.AddListener(tv_qian); mScrollView.AddListener(mIncomeTxt); mScrollView.AddListener(mTotalMoneyTxt); mScrollView.AddListener(mIncTotalTxt); mScrollView.AddListener(mIncSevTxt); mScrollView.AddListener(mIncWeekTxt); mScrollView.AddListener(mIncMonTxt); mScrollView.AddListener(mOverPerTxt); mScrollView.AddListener(mOverPerTxt2); mScrollView.AddListener(mOverCountTxt); } private void onMeasureTxt(MagicTextViewview){ //用来获取view在距离屏幕顶端的距离(屏幕顶端也是scrollView的顶端) view.getLocationInWindow(location); view.setLocHeight(location[ 1 ]); Log.d( "windowyis====>" , "" +location[ 1 ]); } } 总结一下:这个动画需要你自己去计算,我自己的需求是这样的:每一个圆按照120°旋转,坐标分别是(46,50),(53,50+2√3),(53,50-2√3),距上顶点和距左边距。下面是草图,大家自己算算就知道了啊。。另外时间的换算你可以去控制快慢什么的百度吧~属性值这里就不多说了,百度都有~ 最后就是说一句,没有做不出来的东西,只有不用心上进的人~虽然很苦逼,但是都是你的Color Life~ 本文转自 吴雨声 51CTO博客,原文链接:http://blog.51cto.com/liangxiao/1668949,如需转载请自行联系原作者

优秀的个人博客,低调大师

Java实现Web页面前数字字母验证码实现

最近公司做项目开发中用到了验证码实现功能,将实现代码分享出来, 前段页面实现代码: <ul> <li><label>验证码:</label></li> <li> <div> <inputtype="text"name="validateCode"class="login_input"value=""/> <imgid="img"src="${baseURL}/validateCode"onclick="onclickValidateCode(this);"/> </div> </li> </ul> 为了表达清晰,样式部分代码去掉了,大家根据自己的需求,自己添加样式。 页面JS代码:触发变动验证码改变的JS <scripttype="text/javascript"language="javascript"> //请求获取验证码 functiononclickValidateCode(obj){ $(obj).attr("src","${baseURL}/validateCode?"+newDate().getTime()); } </script> 后台 Controller处理: packagecom.njcc.pay.controller.login; importjava.awt.Color; importjava.awt.Font; importjava.awt.Graphics; importjava.awt.p_w_picpath.BufferedImage; importjava.io.IOException; importjava.io.OutputStream; importjava.util.Random; importjavax.p_w_picpathio.ImageIO; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.apache.commons.lang3.math.NumberUtils; importorg.apache.commons.logging.Log; importorg.apache.commons.logging.LogFactory; importorg.springframework.stereotype.Controller; importorg.springframework.web.bind.annotation.RequestMapping; importcom.alibaba.dubbo.common.utils.StringUtils; /** *验证马Controller * *@authorAdministrator * */ @Controller publicclassValidateCodeController{ @SuppressWarnings("unused") privatestaticfinalLogLOG=LogFactory.getLog(ValidateCodeController.class); publicstaticfinalStringVALIDATE_CODE="validateCode"; privateintw=70; privateinth=23; /** *@throwsException *函数功能说明:进入后台登陆页面. * *@参数:@return *@returnString *@throws */ @RequestMapping(value="/validateCode") publicvoidvalidateCode(HttpServletRequestrequest, HttpServletResponseresponse)throwsException{ createImage(request,response); } privatevoidcreateImage(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException{ response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache"); response.setDateHeader("Expires",0); response.setContentType("p_w_picpath/jpeg"); Stringwidth=request.getParameter("width"); Stringheight=request.getParameter("height"); if(StringUtils.isNumeric(width)&&StringUtils.isNumeric(height)){ w=NumberUtils.toInt(width); h=NumberUtils.toInt(height); } BufferedImagep_w_picpath=newBufferedImage(w,h,BufferedImage.TYPE_INT_RGB); Graphicsg=p_w_picpath.getGraphics(); /* *生成背景 */ createBackground(g); /* *生成字符 */ Strings=createCharacter(g); request.getSession().setAttribute(VALIDATE_CODE,s); g.dispose(); OutputStreamout=response.getOutputStream(); ImageIO.write(p_w_picpath,"JPEG",out); out.close(); } /** *生成颜色 *@paramfc *@parambc *@return */ privateColorgetRandColor(intfc,intbc){ intf=fc; intb=bc; Randomrandom=newRandom(); if(f>255){ f=255; } if(b>255){ b=255; } returnnewColor(f+random.nextInt(b-f),f+random.nextInt(b-f),f+random.nextInt(b-f)); } /** *生成背景 *@paramg */ privatevoidcreateBackground(Graphicsg){ //填充背景 g.setColor(getRandColor(220,250)); g.fillRect(0,0,w,h); //加入干扰线条 for(inti=0;i<8;i++){ g.setColor(getRandColor(40,150)); Randomrandom=newRandom(); intx=random.nextInt(w); inty=random.nextInt(h); intx1=random.nextInt(w); inty1=random.nextInt(h); g.drawLine(x,y,x1,y1); } } /** *生成字符 *@paramg *@return */ privateStringcreateCharacter(Graphicsg){ char[]codeSeq={'A','B','C','D','E','F','G','H','J', 'K','M','N','P','Q','R','S','T','U','V','W', 'X','Y','Z','2','3','4','5','6','7','8','9'}; String[]fontTypes={"Arial","ArialBlack","AvantGardeBkBT","Calibri"}; Randomrandom=newRandom(); StringBuilders=newStringBuilder(); for(inti=0;i<4;i++){ Stringr=String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10)); g.setColor(newColor(50+random.nextInt(100),50+random.nextInt(100),50+random.nextInt(100))); g.setFont(newFont(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,26)); g.drawString(r,15*i+5,19+random.nextInt(8)); // g.drawString(r,i*w/4,h-5); s.append(r); } returns.toString(); } }

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册