首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

webvIew 增添手势

2012-09-01 
webvIew 添加手势public class Main extends Activity {/** Called when the activity is first created.

webvIew 添加手势

public class Main extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {? ? super.onCreate(savedInstanceState);? ? MyWebView webview = new MyWebView(this);? ? setContentView(webview);}class MyWebView extends WebView {?Context context;?GestureDetector gd;public MyWebView(Context context) {super(context);this.context = context;? ? ?gd = new GestureDetector(context, sogl);}@Overridepublic boolean onTouchEvent(MotionEvent event) {return gd.onTouchEvent(event);}?GestureDetector.SimpleOnGestureListener sogl = new GestureDetector.SimpleOnGestureListener() {? public boolean onDown(MotionEvent event) {? ?return true;? }? public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {? ?if (event1.getRawX() > event2.getRawX()) {? ? show_toast("swipe left");? ?} else {? ? show_toast("swipe right");? ?}return true;? }?};?void show_toast(final String text) {? Toast t = Toast.makeText(context, text, Toast.LENGTH_SHORT);? t.show();?}}}

1 楼 maniunet 2011-07-25   这样webview左右滑动有了,但是如果webview内容较长的时候,上下的手势不能滚动查看内容了,请问如何能既可以左右滑动,但是不影响webview手势的上下滚动

热点排行