基于原生态 launcher3的5.1源代码进行分析。
- 通过Hierachy view工具,我们知道,Folder布局是在FolderIcon这个文件中进行的,dispatchDraw()这个是关键的地方,在这里我们先打一个log堆栈出来分析下。
java.lang.Throwable
at com.android.launcher3.FolderIcon.computePreviewItemDrawingParams(FolderIcon.java:564)
at com.android.launcher3.FolderIcon.dispatchDraw(FolderIcon.java:645)
at android.view.View.updateDisplayListIfDirty(View.java:14177)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at com.android.launcher3.ShortcutAndWidgetContainer.dispatchDraw(ShortcutAndWidgetContainer.java:93)
at android.view.View.updateDisplayListIfDirty(View.java:14177)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at com.android.launcher3.CellLayout.dispatchDraw(CellLayout.java:518)
at android.view.View.draw(View.java:15249)
at android.view.View.updateDisplayListIfDirty(View.java:14182)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at com.android.launcher3.PagedView.dispatchDraw(PagedView.java:1339)
at android.view.View.draw(View.java:15249)
at android.view.View.updateDisplayListIfDirty(View.java:14182)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at com.android.launcher3.DragLayer.drawChild(DragLayer.java:949)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at com.android.launcher3.DragLayer.dispatchDraw(DragLayer.java:915)
at android.view.View.updateDisplayListIfDirty(View.java:14177)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at android.view.View.draw(View.java:15249)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at android.view.View.updateDisplayListIfDirty(View.java:14182)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at android.view.View.updateDisplayListIfDirty(View.java:14177)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at android.view.View.updateDisplayListIfDirty(View.java:14177)
at android.view.View.getDisplayList(View.java:14204)
at android.view.View.draw(View.java:14974)
at android.view.ViewGroup.drawChild(ViewGroup.java:3457)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3244)
at android.view.View.draw(View.java:15249)
at android.widget.FrameLayout.draw(FrameLayout.java:598)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2667)
at android.view.View.updateDisplayListIfDirty(View.java:14182)
at android.view.View.getDisplayList(View.java:14204)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:273)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:279)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:318)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5895)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$Frame
- 我们来分析pcomputePreviewDrawingParams()
在这里进行一些layout前的各个数据的初始化的一个过程。
private void computePreviewDrawingParams(int drawableSize, int totalSize) {}
所现实的三个小图片大小 :mIntrinsicIconSize=72 ;
Folder文件夹所占用的空间 :mTotalWidth=117 ;
圆形的背景图片大小 :previewSize=90 ;
x坐标 :params.transX = transX;
y坐标 :params.transY = transY;
显示的图标要缩小的比例 :params.scale = totalScale;
params.overlayAlpha = overlayAlpha;
previewPadding=6 ;
mAvailableSpaceInPreview=78 ;
adjustedAvailableSpace=70 ;
unscaledHeight=84 ;
mBaselineIconScale=0.8333333 ;
mBaselineIconSize=60 ;
mMaxPerspectiveShift=10.8
//
3. view的绘制过程
A. draw()
B. onDraw()
C. dispatchDraw()