- package com.example.webviewstudy;
- import android.app.Activity;
- import android.os.Bundle;
- import android.renderscript.Element;
- import android.util.Log;
- import android.view.GestureDetector;
- import android.view.GestureDetector.OnGestureListener;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnTouchListener;
- import android.widget.LinearLayout;
- import android.widget.Toast;
- public class Flay_Activity extends Activity implements OnTouchListener, OnGestureListener{
- LinearLayout layout;
- @SuppressWarnings("deprecation")
- GestureDetector fly = new GestureDetector(this);
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.fliy_test);
-
- layout = (LinearLayout) findViewById(R.id.lineLayout);
- layout.setOnTouchListener(this);
- layout.setFocusable(true);
- layout.setClickable(true);
- layout.setLongClickable(true);
- //layout.setLongClickable(true);
- fly.setIsLongpressEnabled(true);
- }
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- // TODO Auto-generated method stub
- //接触事件
- /* int i = event.getPointerCount();
- Log.i("TAG", i + "--->触点个数");
-
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- Log.i("TAG", "--->触点按下");
- break;
- case MotionEvent.ACTION_MOVE:
- Log.i("TAG", event.getX() + "::" + event.getY() + "--->触点移动");
- break;
- case MotionEvent.ACTION_UP:
- Log.i("TAG", "---->触点释放");
- break;
- default:
- break;
- }*/
- return fly.onTouchEvent(event);
- }
- @Override
- public boolean onDown(MotionEvent e) {
- // TODO Auto-generated method stub
- Log.i("TAG", "---->长按"); //轻按 出发
- return false;
- }
- @Override
- public void onShowPress(MotionEvent e) {
- // TODO Auto-generated method stub
- Log.i("TAG", "---->长按11111111111111"); //重按触发
-
- }
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
- float distanceY) {
- // TODO Auto-generated method stub
- return false;
- }
- @Override
- public void onLongPress(MotionEvent e) {
- // TODO Auto-generated method stub
- Log.i("TAG", "--->长按```````````哼哼按");
-
- }
- @Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
- float velocityY) {
- // TODO Auto-generated method stub
- if(e1.getX() - e2.getX() > 10) {
- Toast.makeText(this, "向左滑动", 1).show();
- return true;
- }
- return false;
- }
- }
复制代码- package com.example.webviewstudy;
- import android.os.Bundle;
- import android.app.Activity;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.Menu;
- import android.webkit.WebView;
- import android.webkit.WebViewClient;
- import android.widget.Toast;
- public class MainActivity extends Activity {
- private WebView webview;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
-
- // WebView(网络视图)能加载显示网页,可以将其视为一个浏览器。它使用了WebKit渲染引擎加载显示网页,实现
- webview = (WebView) findViewById(R.id.webview);
- //能够执行JAviscript脚本
- webview.getSettings().setJavaScriptEnabled(true);
- //加载显示的页面
- webview.loadUrl("http://www.baidu.com/");
- //设置web视图 为了让WebView能够响应超链接功能,调用setWebViewClient( )方法,设置 WebView视图
- webview.setWebViewClient(new WebViewClient() {
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- // TODO Auto-generated method stub
- view.loadUrl(url);
- return super.shouldOverrideUrlLoading(view, url);
- }
-
- });
-
-
- }
- //返回键 最右边的
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
- webview.goBack(); //goBack()表示返回WebView的上一页面
- return true;
- }
- return false;
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
复制代码
感觉人变懒惰了··代码不想解释什么
|