效果如下,打开文件夹时从小到大与最终位置大小吻合,关闭文件夹时缩小到图标原有位置做到无缝融合效果。
过程分析
(一)文件展开后的布局
如上图文件夹打开后布局层次
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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<View
android:id="@+id/folder_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/folder_bg_color" />
<LinearLayout
android: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.ExtendedEditText
android:id="@+id/folder_name"
android:layout_width="@dimen/folder_extended_edit_text_width"
android:layout_height="@dimen/folder_exten