Gmail Android 应用程序如何为邮件对话视图发挥 webview-header-overlay 的魔力?

发布于 2024-12-18 10:56:49 字数 1246 浏览 2 评论 0原文

在 Gmail 对话视图上使用 hierarchyviewer 显示了一个有趣且不寻常的情况布局层次结构:

  • 单个对话中的所有消息都呈现在单个 WebView 中(具体来说是com.google.android.gm.CustomWebView,参见在左边)。仅呈现消息正文 - 标题所在的空格留空
  • WebView 顶部覆盖了一个 com.google.android.gm.MessageHeaderScrollView(如右侧所示),它使用 HybridConversationScrollContainer 来定位 MessageHeaderView code> 位于对话视图中每条消息的正确位置。

CustomWebView <-> MessageHeaderScrollView

那么,这是如何(以及为什么)实现的呢? Android 开发人员可以这样做吗?应该渴望在自己的应用程序中重新创建吗?

显然,可能的原因是性能 - WebView 使用消息文本的快速本机 WebKit 渲染,并且单个 WebView 可能比每条消息的单独 WebView 更高效。如果有人看过有关其性能优势的任何优秀博客文章,我会很感兴趣。

然而,这种方法存在明显的复杂性成本(相对于天真地使用 ExpandableListView 其中包含一些 TextView 或其他内容) - HybridConversationScrollContainer 必须以某种方式计算出消息标头应在网络渲染上的位置,在为了正确定位它的 MessageHeaderViews 。我想知道的是:它是如何计算出这些偏移量的?

Using hierarchyviewer on the Gmail conversation view shows an interesting and unusual layout hierarchy:

  • All messages in a single conversation are rendered in a single WebView (specifically a com.google.android.gm.CustomWebView, seen on the left). Only the body of the messages is rendered - the spaces where the headers would go are left blank.
  • On top of the WebView is overlaid a com.google.android.gm.MessageHeaderScrollView (seen on the right) which uses a HybridConversationScrollContainer to position a MessageHeaderView in the correct position for each message in the conversation view.

CustomWebView <-> MessageHeaderScrollView

So, how (and why) is this achieved? Is it something that an Android developer could & should aspire to re-create in their own apps?

Obviously the probable why is performance - WebView uses the fast native WebKit rendering of the message text, and a single WebView is probably more efficient than a separate WebView for each message. If anyone has seen any good blogposts on the performance benefits of this I'd be interested.

Yet there's an obvious complexity cost to this approach (against naively using an ExpandableListView with some TextViews inside it or whatever) - the HybridConversationScrollContainer has to somehow work out where the message headers should go over the web-rendering, in order to position it's MessageHeaderViews correctly. What I'd like to know is: How does it work out those offsets?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

×眷恋的温暖 2024-12-25 10:56:49

顺便说一句,我能想到的唯一方法是基于 javascript - 在 WebView 中使用 javascript 来收集标题坐标,然后使用 WebView.addJavascriptInterface() 将这些坐标传递给 Java 和 <代码>HybridConversationScrollContainer。我自己还没有尝试过这样做,所以我不确定它是否真的有效。

android 开发者博客上有一篇简短的文章讨论了 addJavascriptInterface() 方法:

http://android-developers.blogspot.com/2008/09/using-webviews.html

如果MessageHeaderScrollView 可以作为开源库发布 - 我会使用它! - 但鉴于 Gmail 应用程序已关闭,这似乎不太可能。

Incidentally, the only approach I can think of is javascript-based - use javascript in the WebView to gather the header coordinates, and then use WebView.addJavascriptInterface() to pass those coordinates on to Java and the HybridConversationScrollContainer. I haven't tried doing this myself though so I'm not sure if it could actually work.

There is a short post on the android Developer blog talking about the addJavascriptInterface() method:

http://android-developers.blogspot.com/2008/09/using-webviews.html

It would be wonderful if MessageHeaderScrollView could be released as an open-source library - I'd use it! - but seeing as the Gmail app is closed, it doesn't seem immediately likely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文