android八方向手势,GitHub - eggyu/GestureDetectorView: 支持8方位的滑动手势检测和缩放手势检测...

GestureDetectorView

支持8方位的滑动手势检测和缩放旋转手势检测

a85a6909caa2607576ffe154593da698.png

示例如下:

xml:

android:id="@+id/gdv_gesture"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:clickable="true"

android:visibility="visible" />

java:

binding.gdvGesture.setOnGestureListener(new GestureDetectorView.OnGestureListener() {

/**

* @param gesture 手势

* @param factor 缩放手势表示缩放因子,滑动手势表示速率,旋转手势表示角度

*/

@Override

public void onGesture( int gesture, float factor) {

switch (gesture) {

case GestureDetectorView.GESTURE_ACTION_UP:

Toast.makeText(MainActivity.this, "action up", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_ACTION_DOWN:

Toast.makeText(MainActivity.this, "action down", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_ACTION_CANCEL:

Toast.makeText(MainActivity.this, "action cancel", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_UP:

Toast.makeText(MainActivity.this, "up", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_DOWN:

Toast.makeText(MainActivity.this, "down", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_LEFT:

Toast.makeText(MainActivity.this, "left", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_RIGHT:

Toast.makeText(MainActivity.this, "right", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_LEFT_UP:

Toast.makeText(MainActivity.this, "left_up", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_LEFT_DOWN:

Toast.makeText(MainActivity.this, "left_down", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_RIGHT_UP:

Toast.makeText(MainActivity.this, "right_up", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SLIDE_RIGHT_DOWN:

Toast.makeText(MainActivity.this, "right_down", Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SCALE_ZOOMIN:

Toast.makeText(MainActivity.this, "zoomin:"+factor, Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_SCALE_ZOOMOUT:

Toast.makeText(MainActivity.this, "zoomout:"+factor, Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_ROTATE_CLOCKWISE:

Toast.makeText(MainActivity.this, "clockwise:"+factor, Toast.LENGTH_SHORT).show();

break;

case GestureDetectorView.GESTURE_ROTATE_ANTICLOCKWISE:

Toast.makeText(MainActivity.this, "anticlockwise:"+factor, Toast.LENGTH_SHORT).show();

break;

}

}

});

说明

此库除系统提供的detector,另外加了两个detector可用:

GestureDetector(系统)

ScaleGestureDetector(系统)

MoveGestureDetector(新加)

RotateGestureDetector(新加)

如果需要用到此库,做法如下:

Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

...

maven { url "https://jitpack.io" }

}

}

and then,add the dependecy:

dependencies {

compile 'com.github.huweijian5:GestureDetectorView:latest_version'

}

其中latest_version请到releases中查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值