FrameLayout 中多余的 onDraw() 调用

发布于 2024-11-13 07:27:57 字数 1651 浏览 8 评论 0原文

我的 xml 中有以下布局结构:

<FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainlayout"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">

    <MyEntireView
            android:id="@+id/map"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
    </MyEntireView>

    <FrameLayout
            android:id="@+id/focusedlayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom">

           <MyDetailedView
              android:id="@+id/focus"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent">
           </MyDetailedView>
    </FrameLayout>
</FrameLayout>

MyEntireView 是一个地图(可绘制),并且 MyDetailedViewonTouch() 上弹出在它的顶部> 并且仅包含整个地图的某一部分(也可绘制),它更详细地显示用户在 MyEntireView 中触摸整个地图的区域。

当显示MyDetailedView时 - 即它的setVisibility(View.VISIBLE) - 顶部会出现一些透明形状(还有一些位图)并定期重绘(例如,1秒间隔) )。这些形状作为 @+id/focusedlayout 的子项动态添加,因为它们的数量始终不同,并且它们的位置与详细地图图片相关。

问题是每个更新都会被处理多次。每次形状更新时,都会调用 MyEntireView 的 onDraw() ,然后调用 MyDetailedView 的 onDraw() ,然后再次调用这两个。只有在此之后,形状本身才会失效。

因此,此行为会使形状闪烁,因为 MyDetailedView 会重绘并隐藏形状 10 毫秒左右。

我可能忽略了一些简单的逻辑,但我真的不知道是否有一种方法可以强制 ViewGroup 中的一个 View 无效()。

或者也许有一种替代结构/布局可以用来满足我的目的?

多谢!

聚苯乙烯 整个代码非常大,无法放在这里,但我愿意根据要求插入任何片段

I have the following layout structure in my xml:

<FrameLayout  xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainlayout"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent">

    <MyEntireView
            android:id="@+id/map"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
    </MyEntireView>

    <FrameLayout
            android:id="@+id/focusedlayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom">

           <MyDetailedView
              android:id="@+id/focus"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent">
           </MyDetailedView>
    </FrameLayout>
</FrameLayout>

MyEntireView is a map (a Drawable) and MyDetailedView pops up on top of it upon onTouch() and contains only a certain piece of the whole map (also Drawable) that displays in greater detail the area which the user touched on the entire map in MyEntireView.

When MyDetailedView is shown - i.e. its setVisibility(View.VISIBLE) - there appear some transparent shapes (also some Bitmaps) on top and are redrawn regularly (e.g., 1 sec interval). The shapes are added dynamically as children of the @+id/focusedlayout as there is always a different number of them and their position is relevant to the detailed map picture.

And the problem is that each single update is processed multiple times. Each time a shape updates, then MyEntireView's onDraw() is called, MyDetailedView's onDraw() is called, and then these two are called again. And only after this the shape itself is invalidated.

As a result, this behaviour makes the shape flicker, since MyDetailedView redraws and hides the shape for 10ms or so.

I must probably be overlooking some simple logic, but I really can't get if there is a way to force only one View of a ViewGroup invalidate().

Or maybe there is an alternate structure/layout that I could use to fit my purpose?

Thanks a lot!

P.S.
The entire code is quite big to put here but I'm willing to insert any pieces upon request

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文