Java實現(xiàn)幀動畫的實例代碼
更新時間:2018年05月15日 16:30:12 作者:meetings
這篇文章主要介紹了Java實現(xiàn)幀動畫的實例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
本文講述了Java實現(xiàn)幀動畫的實例代碼。分享給大家供大家參考,具體如下:
1、效果圖

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

