效果如下,打开文件夹时从小到大与最终位置大小吻合,关闭文件夹时缩小到图标原有位置做到无缝融合效果。

过程分析

(一)文件展开后的布局

如上图文件夹打开后布局层次

1.最下面时背景层(背景不移动但有透明度变化)

2.文件夹编辑控件,文件夹指示器,添加应用程序控件作为倒数第二层(该层有位移,透明度,大小缩放动画)

3.文件夹内容层也带有圆角半透明白色作为背景(该层有位移,大小缩放,文件夹内图标距离移动动画)

问题:

为什么不把背景作为一层,其他的作为一层,因为加上文件夹编辑框和应用添加控件后整体时矩形,如果做缩放动画会有变形效果,另外文件夹编辑和添加应用控件有透明度变化,所以分开处理。

整体布局如下所示

<com.android.launcher3.folder.Folder xmlns:android="http://schemas.android.com/apk/res/android"xmlns:launcher="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"><Viewandroid:id="@+id/folder_bg"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/folder_bg_color" /><LinearLayoutandroid:id="@+id/folder"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center"android:background="@null"android:gravity="center"android:orientation="vertical"android:visibility="visible"><com.android.launcher3.ExtendedEditTextandroid:id="@+id/folder_name"android:layout_width="@dimen/folder_extended_edit_text_width"android:layout_height="@dimen/folder_extended_edit_text_height"android:layout_gravity="center"android:layout_marginBottom="30dp"android:background="@null"android:fontFamily="sans-serif-condensed"android:gravity="center"android:hint="@string/folder_hint_text"android:imeOptions="flagNoExtractUi"android:singleLine="true"android:textColor="@android:color/white"android:textColorHighlight="?android:attr/colorControlHighlight"android:textColorHint="?android:attr/textColorHint"android:textSize="@dimen/folder_label_text_size"android:textStyle="bold" /><LinearLayoutandroid:id="@+id/folder_content_layout"android:layout_width="@dimen/folder_content_layout_width"android:layout_height="@dimen/folder_content_layout_height"android:gravity="center"android:orientation="vertical"><com.android.launcher3.pageindicators.PageIndicatorDotsandroid:id="@+id/folder_page_indicator"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="@dimen/folder_page_dicatorsots_margig_top"android:elevation="1dp"android:gravity="center" /></LinearLayout><TextViewandroid:id="@+id/folder_page_add_application"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:layout_marginTop="80dp"android:drawableStart="@drawable/ic_add_application"android:drawablePadding="12dp"android:gravity="center_vertical"android:paddingTop="7.5dp"android:paddingBottom="7.5dp"android:text="@string/add_application"android:textColor="@android:color/white"android:textSize="14sp" /><LinearLayoutandroid:id="@+id/folder_footer"android:layout_width="match_parent"android:layout_height="wrap_content"android:clipChildren="false"android:orientation="horizontal"android:paddingLeft="12dp"android:paddingRight="12dp"android:visibility="gone"></LinearLayout></LinearLayout><com.android.launcher3.folder.FolderPagedViewandroid:id="@+id/folder_content"android:layout_width="@dimen/folder_paged_view_width"android:layout_height="@dimen/folder_paged_view_height"android:layout_gravity="center"android:background="@drawable/bg_folder_content"android:paddingLeft="8dp"android:paddingTop="@dimen/folder_page_view_margin_top"android:paddingRight="8dp"android:visibility="visible"launcher:pageIndicator="@+id/folder_page_indicator" /></FrameLayout></com.android.launcher3.folder.Folder>

(二)打开关闭文件夹动画分析

打开关闭是两个相反的过程,做好了打开文件夹动画,关闭动画只要参数相反即可。

一,根据上面介绍我们需要做以下几个动画:

1.底层背景透明度变化,桌面隐藏动画

2.中间层文件夹编辑等控件透明度动画

3.中间层文件夹编辑等控件大小位移变化动画

4.顶层文件夹内容大小移动变化动画

5.文件夹内容图标间距大小变化动画

6.文件夹内容图标文字透明度变化动画

7.桌面文件夹图标文字透明度变化动画

二,该过程最麻烦的有两个地方:

(1)计算文件夹起始位置和防缩比例

(2)计算文件夹内图标大小变化和位置

如上图所示要想打开关闭动画与桌面文件夹图标完美融合大小,位置,图标距离,角度都会影响,所以里面所有的位置大小都需要精确计算。

3,桌面文件夹图标起始位置计算

如上图动画起始位置应该是桌面文件夹图标带白透明度圆角白色背景的那一块,而不是整个方块位置。

桌面应用再实现文件夹图标时控件都是继承TextView控件只要给TextView控件添加一个topDrawable图标即可实现,那我们要想计算图标的位置该如何计算呢(不带labe的图标)。

4.图标起始位置计算方法:

1.先获取整个边框位置

mFolderIcon.getGlobalVisibleRect(folderStartBounds)

2.减去上下左右padding

folderStartBounds.top += mFolderIcon.getPaddingTop();
folderStartBounds.left += mFolderIcon.getPaddingLeft();
folderStartBounds.right -= mFolderIcon.getPaddingRight();
folderStartBounds.bottom -= mFolderIcon.getPaddingBottom();

3.计算最终位置

整体图标再边框内是居中显示的只是因为有位置所以高度并不能通过剧中计算但宽度是居中的

folderStartBounds.left = (int) (folderStartBounds.left + width/2-mFolderIcon.mFolderName.getIconSize()/2);
folderStartBounds.right = (int) (folderStartBounds.left + mFolderIcon.mFolderName.getIconSize());
folderStartBounds.top = folderStartBounds.top + mFolderIcon.mFolderName.getPaddingTop();
folderStartBounds.bottom = folderStartBounds.top + mFolderIcon.mFolderName.getIconSize();

4.图标终点位置计算方法:

终点位置相比起点就非常好计算,因为文件夹最终是居中显示的所以我们只要找到屏幕中点再前去文件夹内容的2/1宽高

mLauncher.getDragLayer().getGlobalVisibleRect(temp, globalOffset);
folderFinalBounds.top = (int) (temp.height()/2 - viewPageHeight/2);
folderFinalBounds.bottom = (int) (temp.height()/2 + viewPageHeight/2);
folderFinalBounds.left = (int) (temp.width()/2 - viewPageWidth/2);
folderFinalBounds.right = (int) (temp.width()/2 + viewPageWidth/2);

现在知道了起始位置,终点位置,也知道对应的大小后面只要执行对应的防缩位移动画即可。

private ObjectAnimator animateFolderOffsetScale(View view , Rect folderStartBounds , Rect folderFinalBounds , PointF startScale , PointF finalScale) {PropertyValuesHolder x = null;PropertyValuesHolder y = null;if(folderFinalBounds != null){x = PropertyValuesHolder.ofFloat("x", folderStartBounds.left, folderFinalBounds.left);y = PropertyValuesHolder.ofFloat("y", folderStartBounds.top, folderFinalBounds.top );}else{x = PropertyValuesHolder.ofFloat("x", folderStartBounds.left);y = PropertyValuesHolder.ofFloat("y", folderStartBounds.top);}PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", startScale.x,finalScale.x);PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", startScale.y,finalScale.y);final ObjectAnimator oa =LauncherAnimUtils.ofPropertyValuesHolder(view, x, y, scaleX, scaleY);return oa;}

5.文件夹内图标大小位置计算方法:

该过程相对来说也是复杂,首先要获取到桌面文件夹被每一个图标大小,其次要获取到文件夹内图标展开后大小并且这个要去掉文字标签的大小,文字标签也是一个透明度渐变的过程,所以不能忽略它。

    

因为动画过程时间较短,为了简单一点我没有做空间间距的变化因为图标大小改变的过程间距也会相应改变所以整体效果基本可以满足。

三,总结

因为具体代码较多没贴完整,主要是分析整个过程。要想做好这个动画效果要以下几点需要注意:

1.文件夹布局分层要明确,归类好相同层动画。

2.计算起始文件夹图标位置,因为里面有很多细节容易被忽略。

3.动画执行时机要调整好。

Android 文件夹放大缩小仿IOS融合动画效果相关推荐

  1. Android实现图片放大缩小

    蓝蓝的天 蓝蓝的天,白云朵朵. White clouds in the blue sky. 目录视图 摘要视图 订阅 新版极客头条上线,每天一大波干货     任玉刚:Android开发者的职场规划  ...

  2. win10 android文件夹是什么,windows10系统删除.android文件夹的方法

    为了获得更好的体验,小编将电脑系统升级到了win10正式版.不过,最近小编在使用win10系统时遇到了无法删除.android文件夹的情况.经常一番研究,终于发现了该问题的原因和具体解决方法.接下来, ...

  3. win10 android可以删吗,windows10系统删除.android文件夹的操作介绍

    为了获得更好的体验,小编将电脑系统升级到了 win10正式版 .不过,最近小编在使用win10系统时遇到了无法删除.android文件夹的情况.经常一番研究,终于发现了该问题的原因和具体解决方法.接下 ...

  4. Android设置透明状态栏,仿ios状态栏

    为什么80%的码农都做不了架构师?>>>    Android设置透明状态栏,仿ios状态栏 设置透明状态栏后,效果如下: 我的实现思路是: 在根布局上添加一块布局 添加了一块线性布 ...

  5. 安卓手机/Android11系统无法访问android文件夹下的data目录,怎么解决?

    最近买了个IQOO10,因为现在还在上学,所以没买mate50. 本来鸿蒙系统里文件夹管理得好好的,上了安卓系统,就发现这个android文件夹下的data目录是没权限访问的!???? 于是我上网搜索 ...

  6. 华为android文件夹太大了,别再胡乱清理华为了,花3分钟了解这些文件夹,能立马多出几个G...

    原标题:别再胡乱清理华为了,花3分钟了解这些文件夹,能立马多出几个G 大家都知道,华为手机里拥有很多英文文件夹,那么这些文件夹究竟代表什么意思呢? 今天我们就来讲讲华为手机里的文件夹,删除掉里面一些文 ...

  7. 内存卡android文件夹名称,安卓手机内存卡文件夹英文名称解析——第三方应用类...

    安卓手机内存卡文件夹英文名称解析--第三方应用类: 1..mobo:Moboplayer的缓存文件. 2..QQ:QQ的缓存文件,需要定期清除. 3..quickoffice:quickoffice的 ...

  8. android仿ppt,android 仿ppt进入动画效果合集

    EnterAnimation android 仿ppt进入动画效果合集, 百叶窗效果,擦除效果,盒状效果,阶梯效果,菱形效果,轮子效果,劈裂效果,棋盘效果, 切入效果,扇形展开效果,十字扩展效果,随机 ...

  9. android 仿ppt进入动画效果合集

    EnterAnimation android 仿ppt进入动画效果合集, 百叶窗效果,擦除效果,盒状效果,阶梯效果,菱形效果,轮子效果,劈裂效果,棋盘效果, 切入效果,扇形展开效果,十字扩展效果,随机 ...

最新文章

  1. [K/3Cloud]进度条控件编程接口
  2. 天使投资乱象频出 熟人元素何时剔除
  3. Cpp 对象模型探索 / 编译器为对象创建缺省构造函数的条件
  4. 【Eviews】第九周实验-二次/对数拟合、预测
  5. error: unpacking of archive failed on file错误的解决
  6. NetSet:一款功能强大的自动化网络流量安全增强工具
  7. mysql的常用引擎
  8. TCP粘包/拆包--利用LineBasedFrameDecoder解决TCP粘包问题
  9. MTK 修改ro.hardware 获取cpu 和固件版本号方法
  10. win10安装visio2010出错_Office2010安装过程中提示错误1907的三种解决方法
  11. 实习期间的一些思考整理(5)2018.4.17~4.18
  12. 计算机组成原理基础知识点
  13. LeetCode 6009. 使两字符串互为字母异位词的最少步骤数
  14. 服务器2012不能复制文件夹,windows2012标准版 目录SYSVOL和Netlogon共享和文件同步问题 - 服务器论坛 - 51CTO技术论坛_中国领先的IT技术社区...
  15. Wannafly挑战赛26 御坂网络
  16. python 使用摄像头监测心率
  17. 北京市医疗保障的不用定点的可以医保的医院查询步骤
  18. CPU CACHE中的VIPT与PIPT的工作原理
  19. strstr()函数的使用说明(C语言)
  20. ORACLE RAC TO RAC DG搭建过程中可能遇到的问题

热门文章

  1. 第六课 511遇见易语言大漠找字FindStrFastEx打多怪实例
  2. QT MQTT库在win上和linux上的使用
  3. 搞笑音乐:人在江湖漂
  4. Linux内核中CPU主频和电压调整 (一)
  5. 用python进行按掩膜提取的批量操作
  6. Minecraft国际版下载
  7. Livox Lidar+海康Camera实时生成彩色点云
  8. linux的 vi的各种命令(超级好用)
  9. 复用Oracle数据文件,Oracle控制文件的备份、恢复以及多路复用
  10. 使用VScode调试与编写bash脚本