问题描述
packagecom.wenxiaolang.p141021_01_fling;importandroid.os.Bundle;importandroid.support.v7.app.ActionBarActivity;importandroid.view.GestureDetector;importandroid.view.GestureDetector.OnGestureListener;importandroid.view.Menu;importandroid.view.MenuItem;importandroid.view.MotionEvent;importandroid.view.View;importandroid.view.View.OnTouchListener;importandroid.widget.TextView;importandroid.widget.Toast;publicclassMainActivityextendsActionBarActivityimplementsOnTouchListener,OnGestureListener{privateTextViewtv;privateGestureDetectorgestureDetector;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);tv=(TextView)findViewById(R.id.textView);tv.setOnTouchListener(this);gestureDetector=newGestureDetector(this,this);}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){//Inflatethemenu;thisaddsitemstotheactionbarifitispresent.getMenuInflater().inflate(R.menu.main,menu);returntrue;}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){//Handleactionbaritemclickshere.Theactionbarwill//automaticallyhandleclicksontheHome/Upbutton,solong//asyouspecifyaparentactivityinAndroidManifest.xml.intid=item.getItemId();if(id==R.id.action_settings){returntrue;}returnsuper.onOptionsItemSelected(item);}@OverridepublicbooleanonDown(MotionEvente){Toast.makeText(this,"onDown!",Toast.LENGTH_SHORT).show();returnfalse;}@OverridepublicvoidonShowPress(MotionEvente){Toast.makeText(this,"onShowPress!",Toast.LENGTH_SHORT).show();}@OverridepublicbooleanonSingleTapUp(MotionEvente){Toast.makeText(this,"onSingleTapUp!",Toast.LENGTH_SHORT).show();returnfalse;}@OverridepublicbooleanonScroll(MotionEvente1,MotionEvente2,floatdistanceX,floatdistanceY){Toast.makeText(this,"onScroll!",Toast.LENGTH_SHORT).show();returnfalse;}@OverridepublicvoidonLongPress(MotionEvente){Toast.makeText(this,"onLongPress!",Toast.LENGTH_SHORT).show();}@OverridepublicbooleanonFling(MotionEvente1,MotionEvente2,floatvelocityX,floatvelocityY){Toast.makeText(this,"onFling!",Toast.LENGTH_SHORT).show();returnfalse;}@OverridepublicbooleanonTouch(Viewv,MotionEventevent){returngestureDetector.onTouchEvent(event);}}xml文件:<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.wenxiaolang.p141021_01_fling.MainActivity"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:textSize="30sp"android:text="@string/hello_world"/></RelativeLayout>为什么我点一下的时候依次是onDown-->onShowPress-->onLongpress