日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android实现蝴蝶动画,Android中的动画具体解释系列——飞舞的蝴蝶

發布時間:2024/10/14 Android 114 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android实现蝴蝶动画,Android中的动画具体解释系列——飞舞的蝴蝶 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這一篇來使用逐幀動畫和補間動畫來實現一個小樣例,首先我們來看看Android中的補間動畫。

Android中使用Animation代表抽象的動畫類,該類包含以下幾個子類:

AlphaAnimation:透明改變動畫。

ScaleAnimation:大小縮放動畫。

TranslateAnimation:位移變化動畫。

RotateAnimation:旋轉動畫。

我們以下使用位移動畫和逐幀動畫來實現這個小樣例。先看看執行效果:

蝴蝶揮動翅膀的逐幀動畫文件:

android:oneshot="false">

界面布局文件:

>

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="@drawable/background"

>

android:id="@+id/butterfly"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@anim/butteryfly"

/>

詳細邏輯及位移動畫:

package com.example.butteryfly;

import java.util.Timer;

import java.util.TimerTask;

import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.os.Handler;

import android.view.Display;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.TranslateAnimation;

import android.widget.ImageView;

public class MainActivity extends Activity {

private float curX = 0;

private float curY = 30;

private float nextX = 0;

private float nextY = 0;

private int windowW = 0;

private int windowH = 0;

private ImageView imageView;

Handler handler = new Handler(){

public void handleMessage(android.os.Message msg) {

if(msg.what == 0x123){

if(nextX > windowW || nextY > windowH){

curX = nextX = 0;

}else{

nextX += 8;

}

nextY = curY + (float) (Math.random() * 20 - 10);

TranslateAnimation anim = new TranslateAnimation(curX, nextX, curY, nextY);

curX = nextX;

curY = nextY;

anim.setDuration(200);

imageView.startAnimation(anim);

}

};

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

imageView = (ImageView) findViewById(R.id.butterfly);

Display display = getWindowManager().getDefaultDisplay();

windowW = display.getWidth();

windowH = display.getHeight();

final AnimationDrawable butterfly = (AnimationDrawable) imageView.getBackground();

imageView.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

butterfly.start();

new Timer().schedule(new TimerTask() {

@Override

public void run() {

handler.sendEmptyMessage(0x123);

}

}, 0, 200);

}

});

}

}

總結

以上是生活随笔為你收集整理的Android实现蝴蝶动画,Android中的动画具体解释系列——飞舞的蝴蝶的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。