[安卓]新闻客户端(一)Splash

来源:互联网 发布:ember.js入门教程 编辑:程序博客网 时间:2024/05/16 17:01

这里主要是一个图片实现的动画,并且需要有一个SharedPreferences,并抽成一个工具,来判断是否第一次进入,第一次进入先进入引导页再进入主页

布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/rl_splash_all"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:background="@drawable/splash_bg_newyear">    <ImageView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:src="@drawable/splash_horse_newyear">    </ImageView></RelativeLayout>

需要一个监听器,到了最后一个画面,则需要准备跳转

private void setAnimation() {//第三步  动画效果合集,需要同时生效,但是有彼此不同的时间插值,需要置为falseAnimationSet set = new AnimationSet(false);//第四步(1) 旋转RotateAnimation rotate = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);//相对于自己,两个坐标轴的中点,也就是以图片中心点旋转rotate.setDuration(3000);// 时间rotate.setFillAfter(true);// 留在最后一个帧画面//第四步(2) 缩放ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);scale.setDuration(3000); scale.setFillAfter(true);//第四步(3) 渐变AlphaAnimation alpha = new AlphaAnimation(0, 1);alpha.setDuration(3000);alpha.setFillAfter(true);//第五步(1) 将效果增加到集合里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) {// TODO Auto-generated method stubjumpNextPage();}});//第五步(2) 在整个布局上启动所有动画效果rl_splash_all.startAnimation(set);}


工具

public class PrefUtils {public static final String PREF_NAME = "config";public static boolean getBoolean(Context ctx, String key,boolean defaultValue) {SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,Context.MODE_PRIVATE);return sp.getBoolean(key, defaultValue);}public static void setBoolean(Context ctx, String key, boolean value) {SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME,Context.MODE_PRIVATE);sp.edit().putBoolean(key, value).commit();}}


判断

//第七部 跳转private void jumpNextPage() {//判断之前有没有显示过新手引导boolean userGuide = PrefUtils.getBoolean(this, "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