Fling 手势、Webview 和 Android
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要通过 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.