用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

小火箭动画 Android

2013-11-22 作者: 免费源代码下载整理举报

[android]代码库

package com.spring.lettel;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.Toast;
import android.app.Activity;

/**
 * 三个简单动画
 * 
 * @author wissea
 * 
 */
public class MainActivity extends Activity {
	private Rocket rocket;

	private ImageView rocket_fly;
	private ImageView cloud;
	private ImageView rocket_line;
	private MediaPlayer mediaPlayer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		rocket_fly = (ImageView) findViewById(R.id.fly_rocket);
		cloud = (ImageView) findViewById(R.id.cloud);
		rocket_line = (ImageView) findViewById(R.id.cloud_line);
		rocket = (Rocket) findViewById(R.id.rocket);
		final TranslateAnimation animation = new TranslateAnimation(0, 0, 0,
				-getWindowManager().getDefaultDisplay().getHeight());
		animation.setDuration(1000);
		animation.setFillAfter(true);
		animation.setInterpolator(new AccelerateInterpolator());

		final AlphaAnimation alphaAnimation3 = new AlphaAnimation(1.0f, 0.0f);
		alphaAnimation3.setDuration(1000);
		alphaAnimation3.setFillAfter(true);

		final AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f);
		alphaAnimation.setDuration(500);

		final AlphaAnimation alphaAnimation2 = new AlphaAnimation(0.1f, 1.0f);
		alphaAnimation2.setDuration(500);
		alphaAnimation2.setStartOffset(300);

		alphaAnimation3.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				Toast.makeText(getApplicationContext(), "小火箭灰得太快,我和小伙们都惊呆了...",
						Toast.LENGTH_SHORT).show();
				rocket_fly.setVisibility(View.GONE);
				cloud.setVisibility(View.GONE);
				rocket_line.setVisibility(View.GONE);
				rocket.reset();
			}
		});
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				mediaPlayer = MediaPlayer.create(MainActivity.this,
						R.raw.rocket);
				mediaPlayer.start();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				mediaPlayer.stop();
				mediaPlayer.release();
				cloud.startAnimation(alphaAnimation3);
				rocket_line.startAnimation(alphaAnimation3);
			}
		});

		rocket.setOnChangeListener(new LocationChangeListener() {
			@Override
			public void onchange() {
				rocket_fly.setVisibility(View.VISIBLE);
				cloud.setVisibility(View.VISIBLE);
				rocket_line.setVisibility(View.VISIBLE);
				rocket_fly.startAnimation(animation);
				cloud.startAnimation(alphaAnimation);
				rocket_line.startAnimation(alphaAnimation2);
			}
		});

	}

}

[代码运行效果截图]


小火箭动画 Android

[源代码打包下载]




网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...