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

今天想给小项目里添加一个动态的欢迎界面,看了好多网上的教程,都写得很模糊,或者说得很高大上,让一些初学者难以一下子理解,所以就把我自己的代码和注释给大家看。
其实,这个动画效果叫:补间动画。
一:在res文件夹下新建一个anim文件夹,然后再anim下创建xml代码,如果想要动画效果更绚丽可以把一下都建立了,当然,具体参数看自己的要求写就可以了:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" >
<!--这个事放大或者缩小的效果-->
<scale 
    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"
    />
<!--这个是设置透明度变化的-->
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="2000"/>
<!--这个事设置水平与垂直位移的-->
<translate
android:fromXDelta="0"
android:toXDelta="130"
android:fromYDelta="0"
android:toYDelta="-80"
android:duration="2000"/>
<!--这个事设置旋转的-->
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
</set>
二:上边这些都写好后就可以在方法里使用了,以下是我布局的文件,只是为了测试,所以很简单的一个布局,就是放了一个ImageView:
<RelativeLayout 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"
    tools:context=".WelcomeActivity" >

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

</RelativeLayout>
三:接下来就在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);
}
}
是不是很简单啊。。。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值