项目开发之闪屏页+跳转页面
来源:互联网 发布:java编程思想 在线 编辑:程序博客网 时间:2024/06/05 03:32
怎样做一个app初始界面的闪屏页呢?
第一步要先设置一个背景图片,这里涉及到的知识点有
- 旋转动画
- 缩放动画
- 渐变动画
创建一个SplashActivity和splash_activity.xml文件.
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/splash_bg_newyear"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView1" android:src="@drawable/splash_horse_newyear" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /></RelativeLayout>
现在开始设置动画,首先拿到整体布局
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash_activity); rlroot = (RelativeLayout)findViewById(R.id.rl_root); //这里添加了动画属性,旋转动画 animRotat = new RotateAnimation(0,360, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animRotat.setDuration(1000);//动画时间 animRotat.setFillAfter(true);//保持动画结束状态 //缩放动画 animScale = new ScaleAnimation(0,1,0,1, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); animScale.setDuration(1000);//设置动画时间 animScale.setFillAfter(true);//保持动画结束状态 //渐变动画 animAlpha = new AlphaAnimation(0,1); animAlpha.setDuration(2000);//设置动画时间 animAlpha.setFillAfter(true);//保持动画结束状态 //动画集合 set = new AnimationSet(true); set.addAnimation(animRotat); set.addAnimation(animScale); set.addAnimation(animAlpha); //启动动画 rlroot.startAnimation(set);}这个就是闪屏页的动画.主要用到了RotateAnimation ScaleAnimation AlphaAnimation.跳转页面通过set.setAnimationListener这个方法,在 onAnimationEnd这个方法中开始编写public void onAnimationEnd(Animation animation) { //动画结束,跳转页面 //如果是第一次进入,进入新手引导页 //否则跳转到主页面 /* SharedPreferences sp = getSharedPreferences("config",MODE_PRIVATE); Boolean isFirstEnter = sp.getBoolean("is_first_enter",true);*/ Boolean isFirstEnter = PrefUtils.getBoolean(SplashActivity.this,"is_first_enter",true); Intent intent; if(isFirstEnter){ //跳到新手引导页面 intent = new Intent(getApplicationContext(),GuideActivity.class); }else { //跳到主页面 intent = new Intent(getApplicationContext(),MainActivity.class); } startActivity(intent); finish();//结束当前闪屏应用}
在此期间封装一个sharePerfences的工具类如下
package smartxinhua.com.smartxinhua.utils;import android.content.Context;import android.content.SharedPreferences;/** * 封装的工具类 * SharedPreferences的封装 * Created by Zoe on 2016/11/1. */public class PrefUtils { public static boolean getBoolean(Context ctx,String key,boolean defValue) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); return sp.getBoolean(key,defValue); } public static void setBoolean(Context ctx,String key,boolean value) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); sp.edit().putBoolean(key,value).commit(); } public static void setString(Context ctx,String key,String value) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); sp.edit().putString(key,value).commit(); } public static String getString(Context ctx,String key,String defValue) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); return sp.getString(key,defValue); } public static void setInt(Context ctx,String key,int value) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); sp.edit().putInt(key,value).commit(); } public static int getInt(Context ctx,String key,int defValue) { //ctx为当前activity的对象. SharedPreferences sp = ctx.getSharedPreferences("config",ctx.MODE_PRIVATE); return sp.getInt(key,defValue); }}
创建两个activity,一个是新手引导页面,一个是主界面.这里就不贴具体的代码了.这里是代码地址https://github.com/ZoeSj/SmartXinHua.git.
0 0
- 项目开发之闪屏页+跳转页面
- iOS开发之页面跳转
- android项目之启动页面跳转
- Android之项目开发中在app内Intent意图跳转自己指定的Html5页面
- ios开发系列之页面跳转
- ios开发之Xib的页面跳转
- web项目页面跳转
- 解决ThinkJS项目开发中页面跳转报错问题
- Ionic3项目开发——页面跳转与参数传递
- 安卓仿手机网易新闻app项目开发系列之(六)点击页面跳转和网络路径拼接
- iOS开发页面跳转
- 客户端发现_观影团活动页面开发与客户端新版跳转测试页面开发项目总结
- iphone开发之storyboard页面跳转时传递参数
- JSP开发——JSP页面跳转之sendRedirect方法
- iOS开发之ViewController页面跳转和弹出模态
- iOS开发之跳转至设置页面小功能
- jQuery mobile开发之页面(链接)跳转刷新问题
- Android开发之滑动效果+页面分支跳转
- bzoj 2679: [Usaco2012 Open]Balanced Cow Subsets 折半搜索
- PG的数据类型(一)——数组类型
- HTML页面为什么设置了UTF-8仍然中文乱码
- Java线路
- zabbix中文配置指南
- 项目开发之闪屏页+跳转页面
- linux指令 -- ls
- 无限循环遍历数组(正序|倒序)先加后减原则
- 偏序集-Dilworth定理
- attempt to call global ‘require’ <a nil value>
- 不能做switch()的参数类型
- dnsmasq
- Entity Framework学习(一)CodeFirst入门
- 设计模式之原型模式