GestureDetector手势识别的简单使用

GestureDetector可以用在各种view上来达到自己想要的效果

其简单用法

package com.example.gesturedetector;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @butterknife.Bind(R.id.bt_main_1)
    Button btMain1;
    @butterknife.Bind(R.id.ll_main)
    LinearLayout llMain;
GestureDetector mGestureDetector;
    class MyGestureListener extends GestureDetector.SimpleOnGestureListener{
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if(e1.getY()-e2.getY()>=50){

                Toast.makeText(MainActivity.this, "向上滑动", Toast.LENGTH_SHORT).show();
            }
            if(e1.getY()-e2.getY()<50){

                Toast.makeText(MainActivity.this, "向下滑动", Toast.LENGTH_SHORT).show();
            }



            return super.onFling(e1, e2, velocityX, velocityY);
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        butterknife.ButterKnife.bind(this);
        mGestureDetector=new GestureDetector(new MyGestureListener());
        llMain.setOnTouchListener(new View.OnTouchListener() {
            @Override//可以捕获屏幕出发发生的事件
            public boolean onTouch(View v, MotionEvent event) {
                mGestureDetector.onTouchEvent(event);
                return true;
            }
        });
    }
}


根据摄像头拍摄的人体动作来演奏音乐 ======================================================================== CONSOLE APPLICATION : MusicPlay ======================================================================== AppWizard has created this MusicPlay application for you. This file contains a summary of what you will find in each of the files that make up your MusicPlay application. MusicPlay.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. MusicPlay.cpp This is the main application source file. MusicPlay.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly edited in Microsoft Visual C++. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named MusicPlay.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Visual C++ reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. /////////////////////////////////////////////////////////////////////////////
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安果移不动

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值