Animation -- 实现简单的2D动画:从小到大,旋转出场且透明度由0到1

实现上述开机效果的动画,只需要三步。

1.Activity中的布局文件包含一个ImageView

2.通过welcome_anim.xml为ImageView设置动画效果的

3.ImageView启动动画效果mImageView.startAnimation(mAimation);

 

 

欢迎主界面文件:WelcomeActivity.java

通过Handler启动一个线程实现开机动画结束后,跳转到主activity。

 

public class WelcomeActivity extends Activity {
	private static final String TAG ="LinkGame: WelcomeActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		Log.d(TAG," onCreate()");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		set2DAnim();
		new Handler().postDelayed(new Runnable(){
			@Override
			public void run() {
				// TODO Auto-generated method stub
				Log.d(TAG," run()");
				Intent mIntent = new Intent(WelcomeActivity.this,MainActivity.class);
				startActivity(mIntent);
				WelcomeActivity.this.finish();
			}		
			
		}, 4000);
	}
	
	
	
	public void set2DAnim(){
		Log.d(TAG," set2DAnim()");
		ImageView mImageView = (ImageView)findViewById(R.id.welcome_image);
		final Animation mAimation = AnimationUtils.loadAnimation(this, R.anim.welcome_anim);
		mImageView.startAnimation(mAimation);
		
	}
	


}


 

welcome_anim.xml动画效果文件。

该文件在res/anim目录下。

通过一个set集合定义一组动作合集:透明度alpha,旋转rotate和缩放scale

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:duration="3000"
    android:fillAfter="true">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"/>
    
    <rotate
        android:fromDegrees="0"
        android:toDegrees="1080"
        android:pivotX="50%"
        android:pivotY="50%"/>
    
    <scale
        android:fromXScale="0.0"
        android:toXScale="2.0"
        android:fromYScale="0.0"
        android:toYScale="2.0"
        android:pivotX="50%"
        android:pivotY="50%"/>

    </set>


 

 

WelcomeActivity.java的布局文件:activity_welcome.xml

只包含一个ImageView组件。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center" >

    <ImageView
        android:id="@+id/welcome_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
		android:src="@drawable/ic_launcher"
        />

</LinearLayout>


 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值