Android拋物線下載動畫制作過程
下載動畫經(jīng)常出現(xiàn)在下載需求多的app中,比如游戲下載平臺,應用市場……
先看看效果圖:
實現(xiàn)
private void startAnim() { //以bitmap創(chuàng)建new ImageView iv.setDrawingCacheEnabled(true); Bitmap bitmap = iv.getDrawingCache(); ImageView logo = new ImageView(this); logo.setScaleType(ImageView.ScaleType.FIT_XY); logo.setImageBitmap(bitmap); int[] startLocation = new int[2]; iv.getLocationInWindow(startLocation); end.getLocationInWindow(location_download); setAnim(logo, startLocation, location_download); }
設置動畫
private void setAnim(final ImageView logo, int[] startLocation,int[] location_download) { ViewGroup animMaskLayout = createAnimLayout(); animMaskLayout.addView(logo);// 把動畫小球添加到動畫層 // 計算位移 final View view = addViewToAnimLayout(logo, startLocation); // 動畫位移的X坐標 int endY = location_download[1] - startLocation[1]; // 動畫位移的y坐標 TranslateAnimation translateAnimationX = new TranslateAnimation(0, endX, 0, 0); translateAnimationX.setInterpolator(new LinearInterpolator()); translateAnimationX.setRepeatCount(0);// 動畫重復執(zhí)行的次數(shù) translateAnimationX.setFillAfter(true); TranslateAnimation translateAnimationY = new TranslateAnimation(0, 0, 0, endY); translateAnimationY.setInterpolator(new AccelerateInterpolator()); translateAnimationY.setRepeatCount(0);// 動畫重復執(zhí)行的次數(shù) translateAnimationX.setFillAfter(true); AnimationSet set = new AnimationSet(false); set.setFillAfter(false); set.addAnimation(translateAnimationY); set.addAnimation(translateAnimationX); set.setDuration(2000);// 動畫的執(zhí)行時間 view.startAnimation(set); // 動畫監(jiān)聽事件 set.setAnimationListener(new Animation.AnimationListener() { // 動畫的開始 @Override public void onAnimationStart(Animation animation) { logo.setVisibility(View.VISIBLE); } @Override public void onAnimationRepeat(Animation animation) { } // 動畫的結(jié)束 @Override public void onAnimationEnd(Animation animation) { logo.setVisibility(View.GONE); } }); }
創(chuàng)建動畫父布局
private ViewGroup createAnimLayout() { ViewGroup rootView = (ViewGroup) getWindow().getDecorView(); LinearLayout animLayout = new LinearLayout(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); animLayout.setLayoutParams(lp); animLayout.setId(Integer.MAX_VALUE); animLayout.setBackgroundResource(android.R.color.transparent); rootView.addView(animLayout); return animLayout; }
設置動畫布局參數(shù)
private static View addViewToAnimLayout(final View view, int[] location) { int x = location[0]; int y = location[1]; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(80, 80); lp.leftMargin = x; lp.topMargin = y; view.setLayoutParams(lp); return view; }
代碼就到此結(jié)束了,看起來并不難,動手試試吧。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android編程實現(xiàn)ImageView圖片拋物線動畫效果的方法
- Android使用音頻信息繪制動態(tài)波紋
- Android編程繪制圓形圖片的方法
- Android自定義View之繼承TextView繪制背景
- Android編程之canvas繪制各種圖形(點,直線,弧,圓,橢圓,文字,矩形,多邊形,曲線,圓角矩形)
- Android實現(xiàn)給TableLayou繪制邊框的方法
- Android使用Canvas繪制圓形進度條效果
- Android使用自定義View繪制漸隱漸現(xiàn)動畫
- Android Path繪制貝塞爾曲線實現(xiàn)QQ拖拽泡泡
- Android自定義控件繪制基本圖形基礎入門
- Android編程繪制拋物線的方法示例
相關文章
Androd自定義對話框Dialog視圖及參數(shù)傳遞的實現(xiàn)方法
這篇文章主要介紹了Androd自定義對話框Dialog視圖及參數(shù)傳遞的實現(xiàn)方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-01-01詳解Android中Intent對象與Intent Filter過濾匹配過程
這篇文章主要介紹了Android中Intent對象與Intent Filter過濾匹配過程,感興趣的小伙伴們可以參考一下2015-12-12實現(xiàn)Android 滑動退出Activity的功能
這篇文章主要介紹了實現(xiàn)Android 滑動退出Activity的功能的相關資料,這里提供實例來說明滑動退出應用程序的實現(xiàn)代碼,需要的朋友可以參考下2017-08-08Android之帶group指示器的ExpandableListView(自寫)
Android缺省的ExpandableListView的group header無法固定在界面上,在網(wǎng)上搜索了好多都不盡人意,于是乎在別人的基礎上改進了一點點,原理都差不多2013-06-06Android自定義view實現(xiàn)圓環(huán)效果實例代碼
本文通過實例代碼給大家介紹了Android自定義view實現(xiàn)圓環(huán)效果,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-07-07Android ListView列表優(yōu)化的方法詳解
列表 ListView 是應用中最為常見的組件,而列表往往也會承載很多元素,這時就需要對其進行優(yōu)化。本文介紹了 Flutter ListView 的4個優(yōu)化要點,非常實用,需要的可以參考一下2022-05-05Flutter?web?bridge?通信總結(jié)分析詳解
這篇文章主要為大家介紹了Flutter?web?bridge?通信總結(jié)分析詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-01-01