前言

本文主要给大家介绍了关于Android如何实现移动小球和CircularReveal页面切换动画的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。
效果图如下
是在fragment中跳转activity实现的效果,fragment跳fragment,activity跳activity类似~~
实现过程
重写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", 0), // 动画半径
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", 0),
getIntent().getIntExtra("y", 0) + findViewById(R.id.title).getHeight(),
getIntent().getIntExtra("end_radius", 0),
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绘制跟随手指移动的小球
# Android自定义圆形View实现小球跟随手指移动效果
# Android实现拖动小球跟随手指移动效果
# Android自定义控件实现随手指移动的小球
# Android实现随手指移动小球
# 重写
# 中心点
# 跳转
# 是在
# 相关内容
# 说了
# 不多
# 有一定
# 给大家
# 还有一个
# 这篇文章
# 谢谢大家
# 不知道为什么
# 如何实现
# 使用了
# 有疑问
# switch
# break
# moveY
# false
相关文章:
,如何利用word制作宣传手册?
免费网站制作模板下载,除了易企秀之外还有什么H5平台可以制作H5长页面,最好是免费的?
免费制作海报的网站,哪位做平面的朋友告诉我用什么软件做海报比较好?ps还是cd还是ai这几个软件我都会些我是做网页的?
子杰智能建站系统|零代码开发与AI生成SEO优化指南
,制作一个手机app网站要多少钱?
海南网站制作公司有哪些,海口网是哪家的?
如何用好域名打造高点击率的自主建站?
宁波自助建站系统如何快速打造专业企业网站?
中山网站制作网页,中山新生登记系统登记流程?
弹幕视频网站制作教程下载,弹幕视频网站是什么意思?
官网建站费用明细查询_企业建站套餐价格及收费标准指南
建站10G流量真的够用吗?如何应对访问高峰?
为什么Go需要go mod文件_Go go mod文件作用说明
企业宣传片制作网站有哪些,传媒公司怎么找企业宣传片项目?
建站DNS解析失败?如何正确配置域名服务器?
广州网站设计制作一条龙,广州巨网网络科技有限公司是干什么的?
如何通过cPanel快速搭建网站?
家庭建站与云服务器建站,如何选择更优?
广德云建站网站建设方案与建站流程优化指南
建站主机选哪家性价比最高?
如何在IIS中配置站点IP、端口及主机头?
如何在阿里云域名上完成建站全流程?
网站代码制作软件有哪些,如何生成自己网站的代码?
网站制作网站,深圳做网站哪家比较好?
Swift中循环语句中的转移语句 break 和 continue
建站之星如何一键生成手机站?
寿县云建站:智能SEO优化与多行业模板快速上线指南
建站主机与虚拟主机有何区别?如何选择最优方案?
如何在Golang中使用replace替换模块_指定本地或远程路径
如何在万网主机上快速搭建网站?
较简单的网站制作软件有哪些,手机版网页制作用什么软件?
音响网站制作视频教程,隆霸音响官方网站?
七夕网站制作视频,七夕大促活动怎么报名?
如何选择长沙网站建站模板?H5响应式与品牌定制哪个更优?
如何高效利用200m空间完成建站?
制作电商网页,电商供应链怎么做?
如何打造高效商业网站?建站目的决定转化率
文字头像制作网站推荐软件,醒图能自动配文字吗?
济南网站建设制作公司,室内设计网站一般都有哪些功能?
营销式网站制作方案,销售哪个网站招聘效果最好?
如何用PHP工具快速搭建高效网站?
如何设置并定期更换建站之星安全管理员密码?
深圳网站制作案例,网页的相关名词有哪些?
如何选择高效稳定的ISP建站解决方案?
Python路径拼接规范_跨平台处理说明【指导】
官网自助建站系统:SEO优化+多语言支持,快速搭建专业网站
义乌企业网站制作公司,请问义乌比较好的批发小商品的网站是什么?
建站主机服务器选购指南:轻量应用与VPS配置解析
成都网站制作公司哪家好,四川省职工服务网是做什么用?
在线ppt制作网站有哪些,请推荐几个好的课件下载的网站?
*请认真填写需求信息,我们会在24小时内与您取得联系。