gpt4 book ai didi

android - 使1个自定义 View 失效导致 View 组中所有自定义 View 失效?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:36 24 4
gpt4 key购买 nike

我有一个自定义 View 组。在该自定义 View 组中有许多自定义 View 。自定义 View 在布局上相互重叠。

重叠 View 是为了创建“层”。所以一层可能会创建一些静态内容,但另一个分层 View 会创建不同的动画内容。当我在一个 View 上从另一个线程调用 .postInvalidate 时,问题就来了,该 View 基本上是一个以 60FPS 运行的动画。在分层 View 之外,我使用的设备 (Galaxy S3) 可以达到 60FPS。

在此自定义 View 组中,.invalidate 导致 2 个硬件渲染 View 中的 1 个失效,并且一些软件 View 也随之失效。

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]

最佳答案

View 上的无效会将无效调用链接到 View 层次结构中的父级。如果这是硬件加速的,它可能会根据 HardwareRenderer 类中的标志使所有内容无效。这是一个优化。您可以检查无效实现。这是相关电话的链接 - Invalidate() -check for hardware acceleration

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

关于android - 使1个自定义 View 失效导致 View 组中所有自定义 View 失效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23060967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com