起始页-旋转动画效果

来源:互联网 发布:java int除法向上取整 编辑:程序博客网 时间:2024/06/06 17:08

五块钱在某宝上买到的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布局@Overrideprotected 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() {@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {jumpNextPage();}});rlRoot.startAnimation(set);//给布局添加动画}//设置导航页只显示一次private void jumpNextPage(){//轻量级储存数据的方式sharedpreferencesSharedPreferences 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();}}


0 0
原创粉丝点击