如何在Gmail的Andr​​oid应用程序做的WebView头,覆盖神奇的邮件对话视图?视图、应用程序、神奇、邮件

2023-09-05 01:23:24 作者:十四行诗

使用 hierarchyviewer 对Gmail的会话视图显示了一个有趣的和不寻常的布局层次:

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

所有在一个对话的消息在单的WebView呈现(特别是 com.google.android.gm.CustomWebView ,见左边)。只有消息的身体呈现 - 的空间,其中的头会去留空 。 在web视图的顶部覆盖一个 com.google.android.gm.MessageHeaderScrollView (右图所示),它采用了 HybridConversationScrollContainer 来定位一个 MessageHeaderView 为在对话视图中的每个消息的正确位置。 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.

< - >

<->

那么,如何(为什么)是这样实现的?有什么事情一个Android开发人员可以&放大器;应该立志重新创建自己的应用程序?

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

显然的可能的为什么的是性能 - web视图使用消息文本的快速天然的WebKit渲染,和一个单一的web视图可能比每个消息的独立web视图更有效。如果有人看到了这一性能优势什么好的blogposts我很感兴趣。

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.

然而,有一个明显的复杂性成本,这种方法(对天真地使用 ExpandableListView 里面坐了一些TextViews或其他) - 的 HybridConversationScrollContainer 已以某种方式在哪里工作邮件标题应该通过网络渲染,以便放置它的 MessageHeaderViews 正确。我想知道的是:?如何的它制定出这些偏移

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?

推荐答案

顺便说一句,我能想到的唯一的办法是基于JavaScript的 - 使用JavaScript在web视图采集头坐标,然后用 WebView.addJavascriptInterface()来传递这些坐标上的Java和 HybridConversationScrollContainer 。我还没有尝试这样做我自己,虽然,所以我不知道这是否会实际工作。

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.

目前的是的短后在Android开发者博客谈论 addJavascriptInterface()方法:

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

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

这将是美好的,如果 MessageHeaderScrollView 可能被释放作为一个开放源码库 - 我会用它! - 但看到Gmail应用是封闭的,它似乎并不可能马上

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.