Android的web视图 - 检测头名称作为用户滚动 [英] Android Webview - Detecting the header name as the user scrolls

查看:103
本文介绍了Android的web视图 - 检测头名称作为用户滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此模式中的HTML文件。

I have html files in this pattern.

<a name="header1"></a>
<h2>First Heading</h2>
<a>Some Text goes here</a><br/>
<br/>
<a name="header2"></a>
<h2>Second Heading</h2>
Some Text goes here<br/>
<br/>

这看起来是这样的:

Which Looks like this :

某些文本放在这里

Some Text goes here

某些文本放在这里

Some Text goes here

的ListView ,我在HTML文件中的所有标题的列表,并在此基础上头中的用户选择,我带来了相应的的屏幕上方做 view.loadUrl(JavaScript的:window.location.hash ='+ headerName +')在自定义 WebViewClient onPageFinished 的方法,改变屏幕的标题,在标题栏的 headerName

In a ListView, I have the list of all the headers in the html file and based on which header the user selects, I bring the corresponding header to the top of the screen by doing view.loadUrl("javascript:window.location.hash='" + headerName + "'") in the custom WebViewClient's onPageFinished method and change the title of the screen in the titleBar to the headerName.

现在我的问题是:如果在的ListView 用户选择头1 键,向下滚动到 HEADER2 ,我需要知道用户是在 HEADER2 部分,使屏幕的标题可以改变。我怎么能知道其中的HTML文件的一部分被显示在屏幕上?

Now my problem is : If a user selects header1 in the ListView and scrolls down to header2, I need to know that the user is in the header2 section so that the title of the screen could be changed. How can I know which part of the html file is being shown on the screen?

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

我会使用JavaScript上的setInterval()来监视时,头是针对通过跟踪window.scrollY,并把它比作标题的页面位置(你应该很可能计算和缓存)。提示在页面位置这里。在此之后,从更新的JavaScript窗口的网址,并通过您的WebViewClient的方法跟踪它,你应该准备就绪。

I would use javascript on a setInterval() to monitor when the header was in view by tracking the window.scrollY and comparing it to the page position of the header (which you should likely calculate and cache). Hints on page position here. After that, update the URL of the window from javascript, and track it via your WebViewClient's methods, and you should be all set.

这篇关于Android的web视图 - 检测头名称作为用户滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆