Android应用欢迎界面动态效果设置(补间动画)

今天想给小项目里添加一个动态的欢迎界面,看了好多网上的教程,都写得很模糊,或者说得很高大上,让一些初学者难以一下子理解,所以就把我自己的代码和注释给大家看。
其实,这个动画效果叫:补间动画。
一:在res文件夹下新建一个anim文件夹,然后再anim下创建xml代码,如果想要动画效果更绚丽可以把一下都建立了,当然,具体参数看自己的要求写就可以了:
    android:interpolator="@android:anim/linear_interpolator" >
    android:fromXScale="1.0"
    android:toXScale="1.1"
    android:fromYScale="1.0"
    android:toYScale="1.1"
    android:pivotX="20%"
    android:pivotY="20%"
    android:fillAfter="true"
    android:duration="3500"
    />
android:fromAlpha="1"
android:toAlpha="0"
android:duration="2000"/>
android:fromXDelta="0"
android:toXDelta="130"
android:fromYDelta="0"
android:toYDelta="-80"
android:duration="2000"/>
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
二:上边这些都写好后就可以在方法里使用了,以下是我布局的文件,只是为了测试,所以很简单的一个布局,就是放了一个ImageView:
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".WelcomeActivity" >

   
        android:id="@+id/iv_welcome"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/welcome"
        android:scaleType="centerCrop"
       />

三:接下来就在java代码中使用刚才定义的anim文件中的东东了,代码如下:
package com.example.activity;

import com.example.baozou.R;
import com.example.baozou.R.layout;
import android.os.Bundle;
import android.app.Activity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class WelcomeActivity extends Activity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
iv=(ImageView) findViewById(R.id.iv_welcome);
// 注意:这里就是创建了Animation对象,关联了刚才写的anim文件里的东西
Animation anim=AnimationUtils.loadAnimation(this, R.anim.my_scale);
// 将ImageView对象执行动画就可以了
iv.startAnimation(anim);
}
}
是不是很简单啊。。。

你可能感兴趣的:(Andriod)