android view gesturedetector,如何在Android中利用 GestureDetector进行手势检测

如何在Android中利用 GestureDetector进行手势检测

发布时间:2020-11-26 16:15:21

来源:亿速云

阅读:92

作者:Leah

今天就跟大家聊聊有关如何在Android中利用 GestureDetector进行手势检测,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

一、概述

当用户触摸屏幕的时候,会产生许多手势,例如down,up,scroll,filing等等。

一般情况下,我们知道View类有个View.OnTouchListener内部接口,通过重写他的onTouch(View v, MotionEvent event)方法,我们可以处理一些touch事件,但是这个方法太过简单,如果需要处理一些复杂的手势,用这个接口就会很麻烦(因为我们要自己根据用户触摸的轨迹去判断是什么手势)。

Android sdk给我们提供了GestureDetector(Gesture:手势Detector:识别)类,通过这个类我们可以识别很多的手势,主要是通过他的onTouchEvent(event)方法完成了不同手势的识别。虽然他能识别手势,但是不同的手势要怎么处理,应该是提供给程序员实现的。

GestureDetector这个类对外提供了两个接口和一个外部类

接口:OnGestureListener,OnDoubleTapListener

内部类:SimpleOnGestureListener

这个外部类,其实是两个接口中所有函数的集成,它包含了这两个接口里所有必须要实现的函数而且都已经重写,但所有方法体都是空的;不同点在于:该类是static class,程序员可以在外部继承这个类,重写里面的手势处理方法。

下面我们先看OnGestureListener接口;

二、GestureDetector.OnGestureListener---接口

1、基本讲解如果我们写一个类并implements OnGestureListener,会提示有几个必须重写的函数,加上之后是这个样子的:private class gesturelistener implements GestureDetector.OnGestureListener{

public boolean onDown(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

public void onShowPress(MotionEvent e) {

// TODO Auto-generated method stub

}

public boolean onSingleTapUp(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

public boolean onScroll(MotionEvent e1, MotionEvent e2,

float distanceX, float distanceY) {

// TODO Auto-generated method stub

return false;

}

public void onLongPress(MotionEvent e) {

// TODO Auto-generated method stub

}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

// TODO Auto-generated method stub

return false;

}

}

可见,这里总共重写了六个函数,这些函数都在什么情况下才会触发呢,下面讲一下:

OnDown(MotionEvent e):用户按下屏幕就会触发;

onShowPress(MotionEvent e):如果是按下的时间超过瞬间,而且在按下的时候没有松开或者是拖动的,那么onShowPress就会执行,具体这个瞬间是多久,我也不清楚呃……

onLongPress(MotionEvent e):长按触摸屏,超过一定时长,就会触发这个事件

触发顺序:

onDown->onShowPress->onLongPress

onSingleTapUp(MotionEvent e):从名子也可以看出,一次单独的轻击抬起操作,也就是轻击一下屏幕,立刻抬起来,才会有这个触发,当然,如果除了Down以外还有其它操作,那就不再算是Single操作了,所以也就不会触发这个事件

触发顺序:

点击一下非常快的(不滑动)Touchup:

onDown->onSingleTapUp->onSingleTapConfirmed

点击一下稍微慢点的(不滑动)Touchup:

onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed

onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) :滑屏,用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE, 1个ACTION_UP触发

参数解释:

e1:第1个ACTION_DOWN MotionEvent

e2:最后一个ACTION_MOVE MotionEvent

velocityX:X轴上的移动速度,像素/秒

velocityY:Y轴上的移动速度,像素/秒

onScroll(MotionEvent e1, MotionEvent e2,float distanceX, float distanceY):在屏幕上拖动事件。无论是用手拖动view,或者是以抛的动作滚动,都会多次触发,这个方法在ACTION_MOVE动作发生时就会触发

滑屏:手指触动屏幕后,稍微滑动后立即松开

onDown-----》onScroll----》onScroll----》onScroll----》………----->onFling

拖动:

onDown------》onScroll----》onScroll------》onFiling

可见,无论是滑屏,还是拖动,影响的只是中间OnScroll触发的数量多少而已,最终都会触发onFling事件!

2、实例

要使用GestureDetector,有三步要走:

1.创建OnGestureListener监听函数:

可以使用构造实例:GestureDetector.OnGestureListener listener = new GestureDetector.OnGestureListener(){

};

也可以构造类:private class gestureListener implements GestureDetector.OnGestureListener{

}

2.创建GestureDetector实例mGestureDetector:

构造函数有下面三个,根据需要选择:

GestureDetector gestureDetector=new GestureDetector(GestureDetector.OnGestureListener listener);

GestureDetector gestureDetector=new GestureDetector(Context context,GestureDetector.OnGestureListener listener);

GestureDetector gestureDetector=new GestureDetector(Context context,GestureDetector.SimpleOnGestureListener listener);

3、onTouch(View v, MotionEvent event)中拦截:public boolean onTouch(View v, MotionEvent event) {

return mGestureDetector.onTouchEvent(event);

}

4.控件绑定TextView tv = (TextView)findViewById(R.id.tv);

tv.setOnTouchListener(this);

现在进入实例阶段:

首先,在主布局页面添加一个textView,并将其放大到整屏,方便在其上的手势识别,代码为:

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.example.gesturedetectorinterface.MainActivity" >

android:id="@+id/tv"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_margin="50dip"

android:background="#ff00ff"

android:text="@string/hello_world" />

然后在JAVA代码中,依据上面的三步走原则,写出代码,并在所有的手势下添加上Toast提示并写上Logpublic class MainActivity extends Activity implements OnTouchListener{

private GestureDetector mGestureDetector;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mGestureDetector = new GestureDetector(new gestureListener()); //使用派生自OnGestureListener

TextView tv = (TextView)findViewById(R.id.tv);

tv.setOnTouchListener(this);

tv.setFocusable(true);

tv.setClickable(true);

tv.setLongClickable(true);

}

/*

* 在onTouch()方法中,我们调用GestureDetector的onTouchEvent()方法,将捕捉到的MotionEvent交给GestureDetector

* 来分析是否有合适的callback函数来处理用户的手势

*/

public boolean onTouch(View v, MotionEvent event) {

return mGestureDetector.onTouchEvent(event);

}

private class gestureListener implements GestureDetector.OnGestureListener{

// 用户轻触触摸屏,由1个MotionEvent ACTION_DOWN触发

public boolean onDown(MotionEvent e) {

Log.i("MyGesture", "onDown");

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

return false;

}

/*

* 用户轻触触摸屏,尚未松开或拖动,由一个1个MotionEvent ACTION_DOWN触发

* 注意和onDown()的区别,强调的是没有松开或者拖动的状态

*

* 而onDown也是由一个MotionEventACTION_DOWN触发的,但是他没有任何限制,

* 也就是说当用户点击的时候,首先MotionEventACTION_DOWN,onDown就会执行,

* 如果在按下的瞬间没有松开或者是拖动的时候onShowPress就会执行,如果是按下的时间超过瞬间

* (这块我也不太清楚瞬间的时间差是多少,一般情况下都会执行onShowPress),拖动了,就不执行onShowPress。

*/

public void onShowPress(MotionEvent e) {

Log.i("MyGesture", "onShowPress");

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

}

// 用户(轻触触摸屏后)松开,由一个1个MotionEvent ACTION_UP触发

///轻击一下屏幕,立刻抬起来,才会有这个触发

//从名子也可以看出,一次单独的轻击抬起操作,当然,如果除了Down以外还有其它操作,那就不再算是Single操作了,所以这个事件 就不再响应

public boolean onSingleTapUp(MotionEvent e) {

Log.i("MyGesture", "onSingleTapUp");

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

return true;

}

// 用户按下触摸屏,并拖动,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触发

public boolean onScroll(MotionEvent e1, MotionEvent e2,

float distanceX, float distanceY) {

Log.i("MyGesture22", "onScroll:"+(e2.getX()-e1.getX()) +" "+distanceX);

Toast.makeText(MainActivity.this, "onScroll", Toast.LENGTH_LONG).show();

return true;

}

// 用户长按触摸屏,由多个MotionEvent ACTION_DOWN触发

public void onLongPress(MotionEvent e) {

Log.i("MyGesture", "onLongPress");

Toast.makeText(MainActivity.this, "onLongPress", Toast.LENGTH_LONG).show();

}

// 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE, 1个ACTION_UP触发

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

Log.i("MyGesture", "onFling");

Toast.makeText(MainActivity.this, "onFling", Toast.LENGTH_LONG).show();

return true;

}

};

}

源码在博客底部给出。

三、GestureDetector.OnDoubleTapListener---接口

1、构建

有两种方式设置双击监听:

方法一:新建一个类同时派生自OnGestureListener和OnDoubleTapListener:private class gestureListener implements GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener{

}

方法二:使用GestureDetector::setOnDoubleTapListener();函数设置监听://构建GestureDetector实例

mGestureDetector = new GestureDetector(new gestureListener()); //使用派生自OnGestureListener

private class gestureListener implements GestureDetector.OnGestureListener{

}

//设置双击监听器

mGestureDetector.setOnDoubleTapListener(new doubleTapListener());

private class doubleTapListener implements GestureDetector.OnDoubleTapListener{

}

注意:大家可以看到无论在方法一还是在方法二中,都需要派生自GestureDetector.OnGestureListener,前面我们说过GestureDetector 的构造函数,如下:

GestureDetector gestureDetector=new GestureDetector(GestureDetector.OnGestureListener listener);

GestureDetector gestureDetector=new GestureDetector(Context context,GestureDetector.OnGestureListener listener);

GestureDetector gestureDetector=new GestureDetector(Context context,GestureDetector.SimpleOnGestureListener listener);

可以看到,在构造函数中,除了后面要讲的SimpleOnGestureListener 以外的其它两个构造函数都必须是OnGestureListener的实例。所以要想使用OnDoubleTapListener的几个函数,就必须先实现OnGestureListener。

2、函数讲解

首先看一下OnDoubleTapListener接口必须重写的三个函数:private class doubleTapListener implements GestureDetector.OnDoubleTapListener{

public boolean onSingleTapConfirmed(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

public boolean onDoubleTap(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

public boolean onDoubleTapEvent(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

}

onSingleTapConfirmed(MotionEvent e):单击事件。用来判定该次点击是SingleTap而不是DoubleTap,如果连续点击两次就是DoubleTap手势,如果只点击一次,系统等待一段时间后没有收到第二次点击则判定该次点击为SingleTap而不是DoubleTap,然后触发SingleTapConfirmed事件。触发顺序是:OnDown->OnsingleTapUp->OnsingleTapConfirmed

关于onSingleTapConfirmed和onSingleTapUp的一点区别: OnGestureListener有这样的一个方法onSingleTapUp,和onSingleTapConfirmed容易混淆。二者的区别是:onSingleTapUp,只要手抬起就会执行,而对于onSingleTapConfirmed来说,如果双击的话,则onSingleTapConfirmed不会执行。

onDoubleTap(MotionEvent e):双击事件

onDoubleTapEvent(MotionEvent e):双击间隔中发生的动作。指触发onDoubleTap以后,在双击之间发生的其它动作,包含down、up和move事件;下图是双击一下的Log输出:

0e0a4a358eb16c9687a3120df368fd66.png

两点总结:

1、从上图可以看出,在第二下点击时,先触发OnDoubleTap,然后再触发OnDown(第二次点击)

2、其次在触发OnDoubleTap以后,就开始触发onDoubleTapEvent了,onDoubleTapEvent后面的数字代表了当前的事件,0指ACTION_DOWN,1指ACTION_UP,2 指ACTION_MOVE

在上一个例子的基础上,我们再添加一个双击监听类,实现如下:public class MainActivity extends Activity implements OnTouchListener{

private GestureDetector mGestureDetector;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mGestureDetector = new GestureDetector(new gestureListener()); //使用派生自OnGestureListener

mGestureDetector.setOnDoubleTapListener(new doubleTapListener());

TextView tv = (TextView)findViewById(R.id.tv);

tv.setOnTouchListener(this);

tv.setFocusable(true);

tv.setClickable(true);

tv.setLongClickable(true);

}

/*

* 在onTouch()方法中,我们调用GestureDetector的onTouchEvent()方法,将捕捉到的MotionEvent交给GestureDetector

* 来分析是否有合适的callback函数来处理用户的手势

*/

public boolean onTouch(View v, MotionEvent event) {

return mGestureDetector.onTouchEvent(event);

}

//OnGestureListener监听

private class gestureListener implements GestureDetector.OnGestureListener{

public boolean onDown(MotionEvent e) {

Log.i("MyGesture", "onDown");

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

return false;

}

public void onShowPress(MotionEvent e) {

Log.i("MyGesture", "onShowPress");

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

}

public boolean onSingleTapUp(MotionEvent e) {

Log.i("MyGesture", "onSingleTapUp");

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

return true;

}

public boolean onScroll(MotionEvent e1, MotionEvent e2,

float distanceX, float distanceY) {

Log.i("MyGesture22", "onScroll:"+(e2.getX()-e1.getX()) +" "+distanceX);

Toast.makeText(MainActivity.this, "onScroll", Toast.LENGTH_LONG).show();

return true;

}

public void onLongPress(MotionEvent e) {

Log.i("MyGesture", "onLongPress");

Toast.makeText(MainActivity.this, "onLongPress", Toast.LENGTH_LONG).show();

}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

Log.i("MyGesture", "onFling");

Toast.makeText(MainActivity.this, "onFling", Toast.LENGTH_LONG).show();

return true;

}

};

//OnDoubleTapListener监听

private class doubleTapListener implements GestureDetector.OnDoubleTapListener{

public boolean onSingleTapConfirmed(MotionEvent e) {

Log.i("MyGesture", "onSingleTapConfirmed");

Toast.makeText(MainActivity.this, "onSingleTapConfirmed", Toast.LENGTH_LONG).show();

return true;

}

public boolean onDoubleTap(MotionEvent e) {

Log.i("MyGesture", "onDoubleTap");

Toast.makeText(MainActivity.this, "onDoubleTap", Toast.LENGTH_LONG).show();

return true;

}

public boolean onDoubleTapEvent(MotionEvent e) {

Log.i("MyGesture", "onDoubleTapEvent");

Toast.makeText(MainActivity.this, "onDoubleTapEvent", Toast.LENGTH_LONG).show();

return true;

}

};

}

双击一下,部分截图如下:

34314dbe1c994b05dad0e016174cad25.png

双击所对应的触发事件顺序:

40c17e9b6da2ace10e0bc0d1aec060b0.png

轻轻单击一下,对应的事件触发顺序为:

00ac5ae0c27d8878447d1a2da4f035bd.png

源码在博客底部给出。

四、GestureDetector.SimpleOnGestureListener---类

它与前两个不同的是:

1、这是一个类,在它基础上新建类的话,要用extends派生而不是用implements继承!

2、OnGestureListener和OnDoubleTapListener接口里的函数都是强制必须重写的,即使用不到也要重写出来一个空函数但在SimpleOnGestureListener类的实例或派生类中不必如此,可以根据情况,用到哪个函数就重写哪个函数,因为SimpleOnGestureListener类本身已经实现了这两个接口的所有函数,只是里面全是空的而已。

下面利用SimpleOnGestureListener类来重新实现上面的几个效果,代码如下:public class MainActivity extends Activity implements OnTouchListener {

private GestureDetector mGestureDetector;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mGestureDetector = new GestureDetector(new simpleGestureListener());

TextView tv = (TextView)findViewById(R.id.tv);

tv.setOnTouchListener(this);

tv.setFocusable(true);

tv.setClickable(true);

tv.setLongClickable(true);

}

public boolean onTouch(View v, MotionEvent event) {

// TODO Auto-generated method stub

return mGestureDetector.onTouchEvent(event);

}

private class simpleGestureListener extends

GestureDetector.SimpleOnGestureListener {

/*****OnGestureListener的函数*****/

public boolean onDown(MotionEvent e) {

Log.i("MyGesture", "onDown");

Toast.makeText(MainActivity.this, "onDown", Toast.LENGTH_SHORT)

.show();

return false;

}

public void onShowPress(MotionEvent e) {

Log.i("MyGesture", "onShowPress");

Toast.makeText(MainActivity.this, "onShowPress", Toast.LENGTH_SHORT)

.show();

}

public boolean onSingleTapUp(MotionEvent e) {

Log.i("MyGesture", "onSingleTapUp");

Toast.makeText(MainActivity.this, "onSingleTapUp",

Toast.LENGTH_SHORT).show();

return true;

}

public boolean onScroll(MotionEvent e1, MotionEvent e2,

float distanceX, float distanceY) {

Log.i("MyGesture", "onScroll:" + (e2.getX() - e1.getX()) + " "

+ distanceX);

Toast.makeText(MainActivity.this, "onScroll", Toast.LENGTH_LONG)

.show();

return true;

}

public void onLongPress(MotionEvent e) {

Log.i("MyGesture", "onLongPress");

Toast.makeText(MainActivity.this, "onLongPress", Toast.LENGTH_LONG)

.show();

}

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

Log.i("MyGesture", "onFling");

Toast.makeText(MainActivity.this, "onFling", Toast.LENGTH_LONG)

.show();

return true;

}

/*****OnDoubleTapListener的函数*****/

public boolean onSingleTapConfirmed(MotionEvent e) {

Log.i("MyGesture", "onSingleTapConfirmed");

Toast.makeText(MainActivity.this, "onSingleTapConfirmed",

Toast.LENGTH_LONG).show();

return true;

}

public boolean onDoubleTap(MotionEvent e) {

Log.i("MyGesture", "onDoubleTap");

Toast.makeText(MainActivity.this, "onDoubleTap", Toast.LENGTH_LONG)

.show();

return true;

}

public boolean onDoubleTapEvent(MotionEvent e) {

Log.i("MyGesture", "onDoubleTapEvent");

Toast.makeText(MainActivity.this, "onDoubleTapEvent",

Toast.LENGTH_LONG).show();

return true;

}

}

}

到此,有关GestureDetector的所有基础知识都讲解完了,下面给出一个小应用——识别用户是向左滑还是向右滑!

源码在博客底部给出。

五、OnFling应用——识别向左滑还是向右滑

这部分就有点意思了,可以说是上面知识的一个小应用,我们利用OnFling函数来识别当前用户是在向左滑还是向右滑,从而打出日志。先看下OnFling的参数:

boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY)

参数解释:

e1:第1个ACTION_DOWN MotionEvent

e2:最后一个ACTION_MOVE MotionEvent

velocityX:X轴上的移动速度,像素/秒

velocityY:Y轴上的移动速度,像素/秒

首先,先说一下实现的功能:当用户向左滑动距离超过100px,且滑动速度超过100 px/s时,即判断为向左滑动;向右同理.代码如下:public class MainActivity extends Activity implements OnTouchListener {

private GestureDetector mGestureDetector;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mGestureDetector = new GestureDetector(new simpleGestureListener());

TextView tv = (TextView)findViewById(R.id.tv);

tv.setOnTouchListener(this);

tv.setFocusable(true);

tv.setClickable(true);

tv.setLongClickable(true);

}

public boolean onTouch(View v, MotionEvent event) {

// TODO Auto-generated method stub

return mGestureDetector.onTouchEvent(event);

}

private class simpleGestureListener extends

GestureDetector.SimpleOnGestureListener {

/*****OnGestureListener的函数*****/

final int FLING_MIN_DISTANCE = 100, FLING_MIN_VELOCITY = 200;

// 触发条件 :

// X轴的坐标位移大于FLING_MIN_DISTANCE,且移动速度大于FLING_MIN_VELOCITY个像素/秒

// 参数解释:

// e1:第1个ACTION_DOWN MotionEvent

// e2:最后一个ACTION_MOVE MotionEvent

// velocityX:X轴上的移动速度,像素/秒

// velocityY:Y轴上的移动速度,像素/秒

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE

&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {

// Fling left

Log.i("MyGesture", "Fling left");

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

} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE

&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {

// Fling right

Log.i("MyGesture", "Fling right");

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

}

return true;

}

}

}

看完上述内容,你们对如何在Android中利用 GestureDetector进行手势检测有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/392056.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Ubuntu2204配置samba

0.前情说明 samba服务器主要是用来局域网共享文件的,如果想公网共享可能行不通,我已经踩坑一天了 所以说如果你想满足公网samba共享你就可以不要看下去了 1.参考连接 Ubuntu 安装 Samba 服务器_ubuntu安装samba服务器-CSDN博客 2.安装samba服务 sud…

Java—BIO模型

利用 BIO 模型(传统阻塞 IO 模型)实现多用户访问 源代码 Server类 public class server {public static void main(String[] args) {ExecutorService executorService Executors.newFixedThreadPool(6);try {ServerSocket serverSocketnew ServerSocke…

c++学编程如何锻炼耐力_我如何学习编程:这是一项耐力运动

c学编程如何锻炼耐力by Amy M Haddad通过艾米M哈达德(Amy M Haddad) 我如何学习编程:这是一项耐力运动 (How I’m learning to program: it’s an endurance sport) 为什么我的编程学习轨迹反映了我作为跑步者的训练方式 (Why my learning trajectory for programm…

python处理文本数据

处理文本数据,主要是通过Seris的str访问。遇到NaN时不做任何处理,保留结果为NaN,遇到数字全部处理为NaN。 str是Seris的方法,DataFrame不能直接使用,但是通过索引选择DataFrame中的某一行或者某一列,结果为…

Java系列笔记(4) - JVM监控与调优【转】

Java系列笔记(4) - JVM监控与调优【转】 目录 参数设置收集器搭配启动内存分配监控工具和方法调优方法调优实例 光说不练假把式,学习Java GC机制的目的是为了实用,也就是为了在JVM出现问题时分析原因并解决之。通过学习,我觉得JVM监控与调…

Maven打包排除某个资源或者目录

最近在spark streaming本地调试的时候&#xff0c;引入了一些资源文件&#xff0c;打包的时候需要给排除掉。所以就考虑使用maven的方式 详细参考官方文档&#xff1a;https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html 排除某个资源文件 <…

android发送网络请求没反应,Android无法使用HttpURLConnection发送GET请求

我正在尝试在我的应用程序中使用HttpURLConnection.我将我的请求方法设置为’GET’,但是当我尝试检索输出流时,该方法将更改为’POST’&#xff01;我不确定是什么原因,但是当我使用’POST’发送请求时,我的JSON服务器(我使用JAX-RS)会返回一个空白页面.这是我的代码片段&#…

地图 c-suite_C-Suite的模型

地图 c-suiteWe’ve all seen a great picture capture an audience of stakeholders.我们所有人都看到了吸引利益相关者听众的美好画面。 Let’s just all notice that the lady in the front right is not captivated by the image on the board (Photo by Christina wocin…

框架和库的区别_框架和库之间的区别

框架和库的区别Developers often use the terms “library” and “framework” interchangeably. But there is a difference.开发人员经常互换使用术语“库”和“框架”。 但是有区别。 Both frameworks and libraries are code written by someone else that is used to he…

Java—多线程实现生产者消费者模型

采用线程实现“生产者-消费者”编程的基础模型 源代码 消费者代码&#xff1a; public class Consumer implements Runnable {BlockingQueue<Integer> blockingQueue;int n;CountDownLatch countDownLatch;public Consumer(BlockingQueue<Integer> blockingQueue…

动态链接库.so和静态链接库.a的区别

静态链接库&#xff1a; •扩展名&#xff1a;.a  •编译行为&#xff1a;在编译的时候&#xff0c;将函数库直接整合到执行程序中&#xff08;所以利用静态库编译生成的文档会更大&#xff09; •独立执行的状态&#xff1a;编译成功的可执行文件可以独立运行&#xff0c;不…

华为鸿蒙系统封闭,谷歌正式“除名”华为!“亲儿子”荣耀表示:暂不考虑,鸿蒙OS处境尴尬...

我们都知道&#xff0c;目前智能手机最常用操作系统就是IOS和安卓&#xff0c;占据手机系统超过99%的市场份额。由于IOS系统的封闭性&#xff0c;国内手机厂商基本上都是使用谷歌的开源安卓系统。当然华为也不例外&#xff0c;一直使用的都是安卓系统。可以说&#xff0c;安卓系…

使用vue-cli脚手架搭建简单项目框架

1.首先已经安装了node,最好版本6以上。 2.安装淘宝镜像 大家都知道国内直接使用 npm 的官方镜像是非常慢的&#xff0c;这里推荐使用淘宝 NPM 镜像。这样就可以直接使用cnpm了。 npm install -g cnpm --registryhttps://registry.npm.taobao.org如果过程出差&#xff0c;是否安…

sap中泰国有预扣税设置吗_泰国餐厅密度细分:带有K-means聚类的python

sap中泰国有预扣税设置吗Hi! I am Tung, and this is my first stories for my weekend project. What inspired this project is that I have studied to become data scientist for almost two years now mostly from Youtube, coding sites and of course, Medium ,but my l…

自动化yaml文件_从YAML到TypeScript:开发人员对云自动化的看法

自动化yaml文件The rise of managed cloud services, cloud-native, and serverless applications brings both new possibilities and challenges. More and more practices from software development processes like version control, code review, continuous integration,…

SQL SERVER-Extendevent系统视图

--获得扩展事件的事件select name,description from sys.dm_xe_objects where object_typeevent order by name--获得各事件的字段 select c.name,c.description from sys.dm_xe_object_columns c inner join sys.dm_xe_objects o on o.namec.object_name where o.name…

Java—简单的注册页面

根据所提供的界面&#xff0c;编写 register.html 文件 源代码 empty.jsp <% page contentType"text/html;charsetUTF-8" language"java" %> <html> <head><title>error</title> </head> <body> <H1><…

【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络AlexNet

上周我们用PaddlePaddle和Tensorflow实现了图像分类&#xff0c;分别用自己手写的一个简单的CNN网络simple_cnn和LeNet-5的CNN网络识别cifar-10数据集。在上周的实验表现中&#xff0c;经过200次迭代后的LeNet-5的准确率为60%左右&#xff0c;这个结果差强人意&#xff0c;毕竟…

图片获取像素坐标html,HTML5画布Canvas图片抽取、像素信息获取、命中检测

今天主要介绍canvas中比较强大的功能比如将画布内容抽取为图片获取、修改画布的像素信息以及画布的命中检测首先我仍然需要创建画布图片抽取首先要明确的一点是toDataURL()是canvas对象自身的方法而不是环境对象的这个方法会将canvas的内容抽取为一张图片(base64编码)我们来看一…

CentOS6 下Samba服务器的安装与配置

原地址&#xff1a;http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html 一、简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件&#xff0c;而SMB是Server Message Block的缩写&#xff0c;即为服务器消息块 &#xff0c;SMB主要是作为Microsoft的网…