使1个自定义视图失效导致视图组中的所有自定义视图失效?

我有一个自定义视图组。 在那个自定义视图组中是一些自定义视图。 自定义视图在布局中彼此重叠。

重叠的意见是创造“层”的意义。 因此,一个图层可能会创build一些静态内容,而另一个分层视图会创build不同的animation内容。 问题来了,当我从另一个线程调用.postInvalidate在一个视图,基本上是一个60FPS运行的animation。 在分层视图之外,我正在使用的设备(Galaxy S3)可实现60FPS。

在这个自定义视图组中,.invalidate会导致2个硬件渲染视图中的1个无效,而一些软件视图会使其无效。

MyCustomViewThatShouldNotInvalidate(AbstractDialLayer).onDraw(Canvas) line: 68 MyCustomViewThatShouldNotInvalidate.onDraw(Canvas) line: 79 MyCustomViewThatShouldNotInvalidate(View).draw(Canvas) line: 13650 MyCustomViewThatShouldNotInvalidate(View).draw(Canvas, ViewGroup, long) line: 13534 MyCustomViewGroup(ViewGroup).drawChild(Canvas, View, long) line: 2938 MyCustomViewGroup(ViewGroup).dispatchDraw(Canvas) line: 2808 MyCustomViewGroup(View).buildDrawingCache(boolean) line: 12909 MyCustomViewGroup(View).getDisplayList(DisplayList, boolean) line: 12580 MyCustomViewGroup(View).getDisplayList() line: 12645 RelativeLayout(ViewGroup).dispatchGetDisplayList() line: 2920 RelativeLayout(View).getDisplayList(DisplayList, boolean) line: 12537 RelativeLayout(View).getDisplayList() line: 12645 RelativeLayout(ViewGroup).dispatchGetDisplayList() line: 2920 RelativeLayout(View).getDisplayList(DisplayList, boolean) line: 12537 RelativeLayout(View).getDisplayList() line: 12645 NoSaveStateFrameLayout(ViewGroup).dispatchGetDisplayList() line: 2920 NoSaveStateFrameLayout(View).getDisplayList(DisplayList, boolean) line: 12537 NoSaveStateFrameLayout(View).getDisplayList() line: 12645 ViewPager(ViewGroup).dispatchGetDisplayList() line: 2920 ViewPager(View).getDisplayList(DisplayList, boolean) line: 12537 ViewPager(View).getDisplayList() line: 12645 LinearLayout(ViewGroup).dispatchGetDisplayList() line: 2920 LinearLayout(View).getDisplayList(DisplayList, boolean) line: 12537 LinearLayout(View).getDisplayList() line: 12645 RelativeLayout(ViewGroup).dispatchGetDisplayList() line: 2920 RelativeLayout(View).getDisplayList(DisplayList, boolean) line: 12537 RelativeLayout(View).getDisplayList() line: 12645 NoSaveStateFrameLayout(ViewGroup).dispatchGetDisplayList() line: 2920 NoSaveStateFrameLayout(View).getDisplayList(DisplayList, boolean) line: 12537 NoSaveStateFrameLayout(View).getDisplayList() line: 12645 LinearLayout(ViewGroup).dispatchGetDisplayList() line: 2920 LinearLayout(View).getDisplayList(DisplayList, boolean) line: 12537 LinearLayout(View).getDisplayList() line: 12645 LongPressGestureDetectingFrameLayout(ViewGroup).dispatchGetDisplayList() line: 2920 LongPressGestureDetectingFrameLayout(View).getDisplayList(DisplayList, boolean) line: 12537 LongPressGestureDetectingFrameLayout(View).getDisplayList() line: 12645 FrameLayout(ViewGroup).dispatchGetDisplayList() line: 2920 FrameLayout(View).getDisplayList(DisplayList, boolean) line: 12537 FrameLayout(View).getDisplayList() line: 12645 LinearLayout(ViewGroup).dispatchGetDisplayList() line: 2920 LinearLayout(View).getDisplayList(DisplayList, boolean) line: 12537 LinearLayout(View).getDisplayList() line: 12645 CustomViewAbove(ViewGroup).dispatchGetDisplayList() line: 2920 CustomViewAbove(View).getDisplayList(DisplayList, boolean) line: 12537 CustomViewAbove(View).getDisplayList() line: 12645 SlidingMenu(ViewGroup).dispatchGetDisplayList() line: 2920 SlidingMenu(View).getDisplayList(DisplayList, boolean) line: 12537 SlidingMenu(View).getDisplayList() line: 12645 PhoneWindow$DecorView(ViewGroup).dispatchGetDisplayList() line: 2920 PhoneWindow$DecorView(View).getDisplayList(DisplayList, boolean) line: 12537 PhoneWindow$DecorView(View).getDisplayList() line: 12645 HardwareRenderer$Gl20Renderer(HardwareRenderer$GlRenderer).draw(View, View$AttachInfo, HardwareRenderer$HardwareDrawCallbacks, Rect) line: 1170 ViewRootImpl.draw(boolean) line: 2275 ViewRootImpl.performDraw() line: 2147 ViewRootImpl.performTraversals() line: 1958 ViewRootImpl.doTraversal() line: 1112 ViewRootImpl$TraversalRunnable.run() line: 4474 Choreographer$CallbackRecord.run(long) line: 725 Choreographer.doCallbacks(int, long) line: 555 Choreographer.doFrame(long, int) line: 525 Choreographer$FrameDisplayEventReceiver.run() line: 711 Handler.handleCallback(Message) line: 615 Choreographer$FrameHandler(Handler).dispatchMessage(Message) line: 92 Looper.loop() line: 137 ActivityThread.main(String[]) line: 4918 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 511 ZygoteInit$MethodAndArgsCaller.run() line: 1004 ZygoteInit.main(String[]) line: 771 NativeStart.main(String[]) line: not available [native method] 

Solutions Collecting From Web of "使1个自定义视图失效导致视图组中的所有自定义视图失效?"

视图无效会将无效调用链接到视图层次结构中的父项。 如果这是硬件加速,则可能会使所有内容无效,具体取决于HardwareRenderer类中的标志。 这是一个优化。 你可以检查invalidate实现。 这是一个链接到相关的调用 – 无效() – 检查硬件加速

可以肯定的是,您可以在该应用程序的设备上检查HardwareRenderer.RENDER_DIRTY_REGIONS的值。