起始页-旋转动画效果

五块钱在某宝上买到的android教学视频,如获武林秘籍啊~让我最为佩服的教学视频中对软件的架构能力,纯记录和学习,涉及版权勿喷~

起始页是一个旋转动画效果:


知识点:

1 RelativeLayout

2 ImageView

3 Animation动画设置

4 sharedpreferences轻量级储存数据方式

布局方式使用的是RelativieLayout布局,将“小马”图像压在红色背景图上。

Activity_splash.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splash_bg_newyear"
    android:gravity="top" >

    <ImageView
        android:id="@+id/image1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@drawable/splash_horse_newyear" />

</RelativeLayout>

步骤

1 获取布局id

2  设置动画效果

package com.example.zhihuibj;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

public class SplashActivity extends Activity {

	RelativeLayout rlRoot;//获取RelativeLayout布局	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash);
		rlRoot=(RelativeLayout)findViewById(R.id.rl_root);
		startAnima();
	}
	
	private void startAnima()
	{
		//动画集合
		AnimationSet set = new AnimationSet(false);
		
		//旋转效果
		RotateAnimation rotate =new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		rotate.setDuration(5000);
		rotate.setFillAfter(true);
		
		//缩放
		ScaleAnimation scale= new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		scale.setDuration(5000);
		scale.setFillAfter(true);
		
		//渐变
		AlphaAnimation alpha = new AlphaAnimation(0, 1);
		alpha.setDuration(5000);
		alpha.setFillAfter(true);
		
		set.addAnimation(rotate);
		set.addAnimation(scale);
		set.addAnimation(alpha);
		
		
		
		//设置动画监听
		set.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) {
				
				jumpNextPage();
			}
		});
		
		
		rlRoot.startAnimation(set);//给布局添加动画
	
	}
	
	//设置导航页只显示一次
	private void jumpNextPage()
	{
		//轻量级储存数据的方式sharedpreferences
		SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
		boolean userGuide =sp.getBoolean("is_user_guide_showed", false);
		if(!userGuide)
		{
			startActivity(new Intent(SplashActivity.this,GuideActivity.class));
			
		}
		else
		{
			startActivity(new Intent(SplashActivity.this,MainActivity.class));
		}
		finish();
		
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值