宝贵建议请发送至:wangdehua@itcast.cn©2015黑马程序员版权所有说明:本文档是依据李印东老师给Android41期讲课内容编写。内容包括,智慧北京、屏幕适配、消息推送、科大讯飞语音。备注:需要补充,此文档中的知识点在面试中的情况。功能在工作中如何去做。需要添加json数据。文档要做到学生不看视频都能看懂文档。-编程,始于黑马智慧北京By鸡蛋只有登上山顶,才能看到那边的风光!鸡蛋笔记系列欢迎界面如下图:只有登上山顶,才能看到那边的风光!鸡蛋笔记系列目的:给欢迎界面添加动画。ViewrootView=findViewById(R.id.rl_welcome_root);//动画集合AnimationSetanimationSet=newAnimationSet(false);旋转动画:RotateAnimation代码://旋转动画://最长参数:(fromDegrees,toDegrees,pivotXType,pivotXValue,pivotYType,pivotYValue)//开始角度~结束角度:0~360,pivot:中心点。Animation.RELATIVE_TO_SELF相对于自己RotateAnimationrotateAnim=newRotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);rotateAnim.setDuration(1000);//持续时间rotateAnim.setFillAfter(true);//动画执行完毕后,停留在动画结束的状态下.放大动画:ScaleAnimation//缩放://最长参数:(fromX,toX,fromY,toY,pivotXType,pivotXValue,pivotYType,pivotYValue)//开始缩放值~结束缩放值:从无到有0~1,以中心点缩放ScaleAnimationscaleAnim=newScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);scaleAnim.setDuration(1000);scaleAnim.setFillAfter(true);animationSet.addAnimation(scaleAnim);渐变动画:AlphaAnimation//渐变动画://参数:(fromAlpha,toAlpha)//开始透明值~结束透明值:从没有到有0~1AlphaAnimationalphaAnima=newAlphaAnimation(0,1);alphaAnima.setDuration(2000);alphaAnima.setFillAfter(true);animationSet.addAnimation(alphaAnima);animationSet.setAnimationListener(newMyAnimationListener());rootView.startAnimation(animationSet);//开始执行动画(动画集合)1.1.2全屏设置目的:将欢迎界面设置成全屏模式。Activity清单文件配置增加theme@android:style/Theme.NoTitleBar.Fullscreen只有登上山顶,才能看到那边的风光!鸡蛋笔记系列引导界面如下图:1.2.1如何判断是否是第一次进入程序思路:监听动画结束时,将标志存在本地,利用SharedPreference步骤1:可以写一个缓存类,CacheUthilspublicstaticfinalStringCACHE_FILE_NAME=itheima41_cache;privatestaticSharedPreferencesmSharedPreferences;publicstaticvoidputBoolean(Contextcontext,Stringkey,booleanvalue){if(mSharedPreferences==null){mSharedPreferences=context.getSharedPreferences(CACHE_FILE_NAME,Context.MODE_PRIVATE);}mSharedPreferences.edit().putBoolean(key,value).commit();}/***取出一个boolean类型的值*@paramcontext*@paramkey键*@paramdefValue缺省值*@return*/publicstaticbooleangetBoolean(Contextcontext,Stringkey,booleandefValue){if(mSharedPreferences==null){只有登上山顶,才能看到那边的风光!鸡蛋笔记系列=context.getSharedPreferences(CACHE_FILE_NAME,Context.MODE_PRIVATE);}returnmSharedPreferences.getBoolean(key,defValue);}publicstaticvoidputString(Contextcontext,Stringkey,Stringvalue){if(mSharedPreferences==null){mSharedPreferences=context.getSharedPreferences(CACHE_FILE_NAME,Context.MODE_PRIVATE);}mSharedPreferences.edit().putString(key,value).commit();}publicstaticStringgetString(Contextcontext,Stringkey,StringdefValue){if(mSharedPreferences==null){mSharedPreferences=context.getSharedPreferences(CACHE_FILE_NAME,Context.MODE_PRIVATE);}returnmSharedPreferences.getString(key,defValue);}步骤2:动画classMyAnimationListenerimplementsAnimationListener{@OverridepublicvoidonAnimationEnd(Animationanimation){//动画执行完毕,需要判断是否是第一次打开程序booleanisFirstOpen=CacheUtils.getBoolean(WelcomeUI.this,IS_FIRST_OPEN,true);if(isFirstOpen){//当前是第一次打开,跳转到引导页面System.out.println(跳转到引导页面);startActivity(newIntent(WelcomeUI.this,GuideUI.class));}else{//已经打开过,跳转到主界面System.out.println(跳转到主界面);startActivity(newIntent(WelcomeUI.this,MainUI.class));}finish();}@OverridepublicvoidonAnimationRepeat(Animationanimation){//TODOAuto-generatedmethodstub只有登上山顶,才能看到那边的风光!鸡蛋笔记系列}@OverridepublicvoidonAnimationStart(Animationanimation){}}1.2.2引导界面:GuideUI思路Layout:相对布局,底部有个按钮“开始体验”,按钮下方有个线形布局,显示N个点。适配器代码:classMyAdapterextendsPagerAdapter{@OverridepublicintgetCount(){returnimageViewList.size();}@OverridepublicbooleanisViewFromObject(Viewarg0,Objectarg1){returnarg0==arg1;}/***container就是ViewPager*object就是当前需要被移除的View*/@OverridepublicvoiddestroyItem(ViewGroupcontainer,intposition,Objectobject){//两种方式//mViewPager.removeView(imageViewList.get(position));container.removeView((View)object);}@OverridepublicObjectinstantiateItem(ViewGroupcontainer,intposition){//把ImageView添加到ViewPager中,并且把ImageView返回回去.ImageViewimageView=imageViewList.get(position);container.addView(imageView);returnimageView;}}注意点:PagerAdapter的destoryItem方法的super需要去掉,因为父类的代码时直接抛了个异常publicvoiddestroyItem(Viewcontainer,intposition,Objectobject){thrownewUnsupportedOperationException(RequiredmethoddestroyItemwasnotoverridden);}只有登上山顶,才能看到那边的风光!鸡蛋笔记系列初始化数据代码:privatevoidinitData(){int[]imageResIDs={R.drawable.guide_1,R.drawable.guide_2,R.drawable.guide_3};imageViewList=newArrayListImageView();ImageViewiv;Viewv;for(inti=0;iimageResIDs.length;i++){iv=newImageView(this);iv.setBackgroundResource(imageResIDs[i]);imageViewList.add(iv);//每循环一次,向LinearLayout布局中添加一个View.v=newView(this);v.setBackgroundResource(R.drawable.point_normal);LayoutParamsparams