Fling 手势、Webview 和 Android

发布于 2024-10-03 19:08:32 字数 1141 浏览 0 评论 0原文

我有一个 webview 控件,需要支持 Android 中的 fling 手势,以便调出新记录(加载新数据)。这是在扩展 Activity 的类中发生的。我见过的所有示例都展示了如何为文本视图实现手势支持,但没有为网络视图实现手势支持。据我所知,Webview 是另一种动物,而且它很“复杂”。

我需要对左右滑动执行不同的操作。任何代码帮助将不胜感激,因为这完全让我难住了。

这是我的基本 onCreate 和我的课程

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import android.webkit.WebView;

public class ArticleActivity extends Activity   {

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);



  Window  w = getWindow();

   w.requestFeature(Window.FEATURE_LEFT_ICON);

   WebView webview = new WebView(this);
  setContentView(webview); 



   w.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
   R.drawable.gq);




  setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
  populateFields();
webview.loadData(question + answer, "text/html", "utf-8");



//   
}
    private void populateFields() {

....


}

}

I have a webview control that needs to support the fling gesture in Android in order to bring up a new record (load new data). This is occuring in a class that extends Activity. All the examples I've seen show how to implement gesture support for a textview, but nothing for webview. From what I've read Webview is another animal and it is "complicated".

I need to execute different actions for both left and right flings. Any code help would be appreciated as this totally has me stumped.

Here's my basic onCreate and my class

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;

import android.webkit.WebView;

public class ArticleActivity extends Activity   {

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);



  Window  w = getWindow();

   w.requestFeature(Window.FEATURE_LEFT_ICON);

   WebView webview = new WebView(this);
  setContentView(webview); 



   w.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
   R.drawable.gq);




  setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
  populateFields();
webview.loadData(question + answer, "text/html", "utf-8");



//   
}
    private void populateFields() {

....


}

}

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

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

发布评论

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

评论(1

提赋 2024-10-10 19:08:32

您需要通过 web 视图以外的不同视图来捕获手势。将webview包裹在一个线性布局中,让线性布局捕获手势,然后让事件传递给webview。

You need to catch the gesture by a different view other than a webview. Wrap the webview in a linearlayout, have the linearlayout catch the gesture, and then let the event pass to the webview.

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