带动画的欢迎界面的实现

2 篇文章 0 订阅
1 篇文章 0 订阅

1.先找到欢迎界面的控件ImageView

2.初始化动画

3.控件ImageView设置步骤2的动画

4.动画设置监听事件,动画结束跳转

 

 

 

淡入淡出动画文件:

<span style="font-size:18px;">fade_in.xml</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
   android:fromAlpha="0.0"
   android:toAlpha="1.0" 
   android:duration="500">
</alpha>

</span>
<span style="font-size:18px;"></span> 
<pre class="html" name="code"><span style="font-size:18px;">fade_out.xml</span>
 
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android" 
   android:fromAlpha="1.0"
   android:toAlpha="0.0" 
   android:duration="500">
</alpha>

</span>
<span style="font-size:18px;"></span> 
<span style="font-size:18px;"></span> 
<span style="font-size:18px;">fadein.xml</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

</span>




 

 

欢迎界面布局:

<span style="font-size:18px;"><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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.test.MainActivity" >

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

</RelativeLayout>
</span>


 

 

欢迎界面逻辑代码文件:

<span style="font-size:18px;">package com.example.test;

import android.R.animator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class MainActivity extends Activity {

	ImageView iv;
	Animation animation;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		init();
		setListener();
	}


	private void init() {
		animation=AnimationUtils.loadAnimation(getBaseContext(), R.anim.fadein);
		animation.setDuration(1000);
		animation.setFillAfter(true);//设为true之后,界面会停留在动画播放完时的界面
		
		iv=(ImageView) findViewById(R.id.iv);
		iv.setAnimation(animation);
	}
	
	private void setListener() {
		animation.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				Intent intent=new Intent();
				intent.setClass(getBaseContext(), SecondActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
				finish();
			}
		});
	}

}
</span>


 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值