5.void removeEntry(String entryName):删除手势库中entryName对应的手势
代码示例:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns: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" tools:context="com.zking.g150715_android21_gesture.MainActivity"> <ViewFlipper android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/vf_main_image" > </ViewFlipper> </LinearLayout>
----MainAcitvity.java
package com.zking.g150715_android21_gesture; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.ImageView; import android.widget.Toast; import android.widget.ViewFlipper; public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener{ private ViewFlipper vf_main_image; private int images[]={R.drawable.s1,R.drawable.s2,R.drawable.s3}; private GestureDetector gesture; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vf_main_image = (ViewFlipper) findViewById(R.id.vf_main_image); //给ViewFilpper设置适配器(不能) for (int i = 0; i < images.length; i++) { ImageView iv=new ImageView(this); iv.setImageResource(images[i]); vf_main_image.addView(iv); } //实例化一个手势检测器的类 gesture = new GestureDetector(this,this); } @Override public boolean onTouchEvent(MotionEvent event) { return gesture.onTouchEvent(event); } @Override public boolean onDown(MotionEvent motionEvent) { Log.i("test","按下"); return false; } @Override public void onShowPress(MotionEvent motionEvent) { Log.i("test","按下,按下但是还没有开始移动"); } @Override public boolean onSingleTapUp(MotionEvent motionEvent) { Log.i("test","按一下"); return false; } @Override public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) { Log.i("test","滑动"); return false; } @Override public void onLongPress(MotionEvent motionEvent) { Log.i("test","长按"); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) { if(e1.getX()-e2.getX()>=200){ Toast.makeText(MainActivity.this, "←←←←←", Toast.LENGTH_SHORT).show(); vf_main_image.showNext();//下一张 //左出左进 vf_main_image.setOutAnimation(this,R.anim.left_out); vf_main_image.setInAnimation(this,R.anim.left_in); }else if(e2.getX()-e1.getX()>=200){ Toast.makeText(MainActivity.this, "→→→→→", Toast.LENGTH_SHORT).show(); vf_main_image.showPrevious();//上一张 //右出右进 vf_main_image.setOutAnimation(this,R.anim.right_out); vf_main_image.setInAnimation(this,R.anim.right_in); } return false; } }