Java實(shí)現(xiàn)幀動(dòng)畫的實(shí)例代碼
本文講述了Java實(shí)現(xiàn)幀動(dòng)畫的實(shí)例代碼。分享給大家供大家參考,具體如下:
1、效果圖
2、幀動(dòng)畫的簡要代碼
private ImageView bgAnimView; private AnimationDrawable mAnimationDrawable; //初始化 mAnimationDrawable = new AnimationDrawable(); bgAnimView = new ImageView(mContext); bgAnimView.setBackgroundDrawable(getAnimationDrawable(mAnimationDrawable)); params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.topMargin = Util.Div(176 + 58); params.gravity = Gravity.CENTER_HORIZONTAL; addView(bgAnimView, params); private AnimationDrawable getAnimationDrawable(AnimationDrawable mAnimationDrawable) { int duration = 50; mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading1), duration); mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading2), duration); mAnimationDrawable.addFrame(mContext.getResources().getDrawable(R.drawable.loading3), duration); mAnimationDrawable.setOneShot(false); return mAnimationDrawable; } //動(dòng)畫開始 public void animLoadingStart() { this.setVisibility(View.VISIBLE); if (mAnimationDrawable != null) { mAnimationDrawable.start(); } } //動(dòng)畫結(jié)束 public void animLoadingEnd() { if (mAnimationDrawable != null) { mAnimationDrawable.stop(); }
3、擴(kuò)展:
//X軸平移 public void animY(int y, int nextY, int duration) { LinearInterpolator ll = new LinearInterpolator(); //勻速 ObjectAnimator animator = ObjectAnimator.ofFloat(yourView, "translationY", 0, 300);//300若為負(fù)值,就是向上平移 animator.setDuration(duration); animator.setInterpolator(ll); animator.start(); } //Y軸平移 public void animX(int x, int nextX, int duration) { LinearInterpolator ll = new LinearInterpolator(); ObjectAnimator animator = ObjectAnimator.ofFloat(yourView, "translationX", x, nextX); animator.setDuration(duration); animator.setInterpolator(ll); animator.start(); } //縱向壓縮0.5倍 LinearInterpolator ll = new LinearInterpolator();//勻速 ScaleAnimation scaleAnimation = new ScaleAnimation(1, 1, 1, 0.5f);//默認(rèn)從(0,0) scaleAnimation.setDuration(500); scaleAnimation.setInterpolator(ll); scaleAnimation.setFillAfter(true); chartView.startAnimation(scaleAnimation); //橫向壓縮0.5倍 LinearInterpolator ll = new LinearInterpolator(); ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.5f, 1, 1);//默認(rèn)從(0,0) scaleAnimation.setDuration(500); scaleAnimation.setInterpolator(ll); scaleAnimation.setFillAfter(true); chartView.startAnimation(scaleAnimation);
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
Springboot中@Value注解的場景用法及可能遇到的問題詳解
這篇文章主要給大家介紹了關(guān)于Springboot中@Value注解的場景用法及可能遇到問題的相關(guān)資料, @Value通常用于注入外部化屬性,即外部配置屬性的注入,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11淺析SpringBoot多數(shù)據(jù)源實(shí)現(xiàn)方案
現(xiàn)在很多項(xiàng)目的開發(fā)過程中,可能涉及到多個(gè)數(shù)據(jù)源,像讀寫分離的場景,或者因?yàn)闃I(yè)務(wù)復(fù)雜,導(dǎo)致不同的業(yè)務(wù)部署在不同的數(shù)據(jù)庫上,那么這樣的場景,我們應(yīng)該如何在代碼中簡潔方便的切換數(shù)據(jù)源呢,本文介紹SpringBoot多數(shù)據(jù)源實(shí)現(xiàn)方案,感興趣的朋友跟隨小編一起看看吧2024-02-02Springboot+Shiro+Jwt實(shí)現(xiàn)權(quán)限控制的項(xiàng)目實(shí)踐
如今的互聯(lián)網(wǎng)已經(jīng)成為前后端分離的時(shí)代,所以本文在使用SpringBoot整合Shiro框架的時(shí)候會(huì)聯(lián)合JWT一起搭配使用,具有一定的參考價(jià)值,感興趣的可以了解一下2023-09-09Java實(shí)現(xiàn)學(xué)生管理系統(tǒng)(IO版)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)學(xué)生管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02解決微服務(wù)feign調(diào)用添加token的問題
這篇文章主要介紹了解決微服務(wù)feign調(diào)用添加token的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06