前言
本文主要给大家介绍了关于AndroID如何实现移动小球和CircularReveal页面切换动画的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。
效果图如下
是在fragment中跳转activity实现的效果,fragment跳fragment,activity跳activity类似~~
实现过程
重写floatingActionbutton的ontouchListener()方法,使小球可以移动,并判断边界 点击fab时记录坐标传到下一个页面,在下一个页面展示动画。 点击后退或者重写onBackpressed()方法,执行动画重写Fab的ontouchListener()
floatingActionbutton.setontouchListener(new VIEw.OntouchListener() { @OverrIDe public boolean ontouch(VIEw vIEw,MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: downX = ev.getX(); downY = ev.getY(); isClick = true; break; case MotionEvent.ACTION_MOVE: isClick = false; moveX = ev.getX(); moveY = ev.getY(); int offsetX = (int) (moveX - downX); int offsetY = (int) (moveY - downY); //这里使用了setTranslation来移动vIEw。。。尝试过layout。不知道为什么fragment切换回来的时候会恢复原位 floatingActionbutton.setTranslationX(floatingActionbutton.getTranslationX() + offsetX); floatingActionbutton.setTranslationY(floatingActionbutton.getTranslationY() + offsetY); break; case MotionEvent.ACTION_UP: //用来触发点击事件 if (isClick) { startAct(); return false; } //用来判断移动边界 if (floatingActionbutton.getX() < 0) { floatingActionbutton.setX(0); } if (floatingActionbutton.getX() + floatingActionbutton.getWIDth() > ScreenUtil.getScreenWIDth(getContext())) { floatingActionbutton.setX(ScreenUtil.getScreenWIDth(getContext()) - floatingActionbutton.getWIDth()); } if (floatingActionbutton.getY() < TitleHeight) { floatingActionbutton.setY(0); } if (floatingActionbutton.getY() + floatingActionbutton.getHeight() + TitleHeight > getActivity().findVIEwByID(R.ID.activity_main_mainLl).getHeight() - getActivity().findVIEwByID(R.ID.fc_rg).getHeight()) { floatingActionbutton.setY(getBottomY()); } break; } return true; } private voID startAct() { //跳转Activity,传递动画参数 Intent intent = new Intent(getActivity(),CheckWorkActivity.class); intent.putExtra("x",(int) floatingActionbutton.getX() + floatingActionbutton.getWIDth() / 2); intent.putExtra("y",(int) floatingActionbutton.getY() + floatingActionbutton.getHeight() / 2); intent.putExtra("start_radius",floatingActionbutton.getWIDth() / 2); intent.putExtra("end_radius",DialogFragment.this.vIEw.getHeight()); startActivity(intent); } });
在下一个页面中实现CircleRevel动画
onCrete中调用
private voID initAnimation() { //ll为根布局 final linearLayout linearLayout = (linearLayout) findVIEwByID(R.ID.ll); linearLayout.post(new Runnable() { @OverrIDe public voID run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LolliPOP) { Animator animator = VIEwAnimationUtils.createCircularReveal( linearLayout,// *** 作的视图 getIntent().getIntExtra("x",0),// 动画的中心点X getIntent().getIntExtra("y",0) + findVIEwByID(R.ID.Title).getHeight(),// 动画的中心点Y getIntent().getIntExtra("start_radius",// 动画半径 getIntent().getIntExtra("end_radius",0) // 动画结束半径 ); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(500); animator.start(); } } }); }
点击后退或者触发onBackpressed时候调用
private voID endAnim() { final linearLayout linearLayout = (linearLayout) findVIEwByID(R.ID.ll); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LolliPOP) { Animator animator = VIEwAnimationUtils.createCircularReveal( linearLayout,// *** 作的视图 getIntent().getIntExtra("x",getIntent().getIntExtra("y",getIntent().getIntExtra("end_radius",getIntent().getIntExtra("start_radius",0) ); animator.setInterpolator(new AccelerateInterpolator()); animator.setDuration(500); animator.addListener(new AnimatorListenerAdapter() { @OverrIDe public voID onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); finish(); } }); animator.start(); } }
还有一个重要的地方是修改两个activity的theme
<style name="AppthemeCircleRevel" parent="theme.AppCompat.light.NoActionbar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/blue</item> <item name="androID:windowAnimationStyle">@null</item> <item name="androID:windowBackground">@androID:color/transparent</item> <item name="androID:windowIsTranslucent">true</item> <item name="androID:colorBackgroundCacheHint">@null</item> </style>
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对编程小技巧的支持。
总结以上是内存溢出为你收集整理的Android实现移动小球和CircularReveal页面切换动画实例代码全部内容,希望文章能够帮你解决Android实现移动小球和CircularReveal页面切换动画实例代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)