寻找具有多个 WebView 的 Android ViewFlipper 示例
我相信你们都知道。设置 WebView 就是创建 WebView 浏览器客户端、设置属性并将资源加载到浏览器客户端中。我已经创建了几个 Android 应用程序来实现这一点。
我现在想尝试的是水平滑动不同的网络资源。想象一下一个 url 上有一个主页,另一个 url 上有一个类别页面,另一个 url 上有一个搜索页面。我想创建一个 UI 构造,允许从主主页 url 视图滑动到显示类别 url 的视图,然后再滑动显示带有搜索资源的视图(想想新的 android market UI - 向左滑动显示类别) 。
我已经阅读了 ViewFlipper 和这里的几篇文章,但我无法找到如何将浏览器实例化与视图翻转/滑动集成的全面示例。
问题:有人可以提供一个可以执行上述某些变体的示例和/或提供一个示例的链接,该示例显示通过 Web 视图翻转/滑动的浏览器实例化。
请随意纠正我建议的实现...可能有更好的方法来做到这一点,我还没有考虑过...
As I am sure you all know. Setting up a WebView is a matter of creating a webview browser client, setting properties and loading a resource into the browser client. I have created several android apps that do exactly that.
What i would like to try now is horizontal swiping of different web resources. Imagine a main home page at one url, a categories page at another url and a search page at another url. I would like to create a UI construct that allows swiping from the main home page url view to a view displaying the categories url and then another swipe that shows the view with the search resource (think the new android market UI - swipe left shows categories).
I have read up on ViewFlipper and several posts here, but I am not able to find a comprehensive example of how to integrate the browser instantiation with view flipping/swiping.
Question: Can someone provide an example that can perform some variation of the above and/or provide a link to an example that shows browser instantiation with web view flipping/ swiping.
Feel free to correct my suggested implementation... there may be a better way to do this that I haven't considered yet...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我已经为此工作了一段时间并且我有一个有效的解决方案。我不确定这是最有效的解决方案,但我一直在研究和编写代码,直到找到有意义的东西。通过以下代码,我需要对 Android & 大声喊叫。阿米尔在 http://android-journey.blogspot.com/2010/01/android-webview。 html 帮助我解决这个问题。他有一些很棒的东西,你们都应该看看。
第一步是在 Activity 包中创建一个名为 SimpleGestureFilter 的类,并使用此处找到的代码。这直接来自 Amir,极大地简化了滑动的手势交互。
下一步是使用 ViewFlipper 进行布局。我使用了按钮和其他一些东西,因此这个布局文件中的内容超出了必要的范围,但您应该明白了。
正如您所看到的,该 xml 描述了一个包含 ViewFlipper 的线性布局。在视图翻转器中有三个 WebView。
最后一步是活动...
所以...我想出的基本模式是使用单个 Web 客户端和浏览器设置。我使用 onCreate 方法加载视图,设置第一个视图,然后在加载主视图后使用异步方法加载其他视图。因此两个视图在后台加载。我使用阿米尔传承的模式来管理滑动。我使用按钮和 JS 接口在单击时调用相同的动画。
最终结果是 ViewFlipping webview 的滑动和单击动画,类似于您将在新的 android market UI 中看到的 UI。请随意推荐任何可能使此模式更强大的其他实现。
Well, I've worked on this for some time and I have a solution that works. I am not sure it is the most effective solution, but I just kept researching and writing code until I figured out something that made sense. With the following code I need to give a big shout out to Android & Amir at http://android-journey.blogspot.com/2010/01/android-webview.html for helping me figure this out. He's got some great stuff and you all should check it out.
The first step is to create a class in your Activity package called SimpleGestureFilter and use the code found here. This comes directly from Amir and dramatically simplifies the gesture interactions for swipe.
The next step is to use ViewFlipper for your layout. I was using buttons and several other things so there is more in this layout file than necessary, but you should get the picture.
As you can see, the xml describes a linear layout that contains a ViewFlipper. In the view flipper there are three WebViews.
The final step is the Activity...
So... The basic pattern I came up with is to use a single web client and browser settings. I use the onCreate method to load the views, set the first view and then an Async method to load the other views after the main view is loaded. So two of the views load in the background. I them use the patterns Amir passed on to manage swipe. I use buttons and JS interfaces to invoke the same animations on clicks.
The final result is swipe and click animations for ViewFlipping webviews similar to the UI you'll see in the new android market UI. Feel free to recommend any additional implementation that might make this pattern stronger.