有没有办法可以将侦听器添加到布局或视图中,当用户触摸屏幕时,它会添加计数。像
这样的东西 tvTouchCount.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int count = 0;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
count = count + 1;
if (count > maxCount)
maxCount = count;
tvTouchCount.setText("Max Count=" + maxCount);
return false;
case MotionEvent.ACTION_UP:
count = count - 1;
return false;
default:
return false;
}
}
});
我已经尝试从软件包管理器获取详细信息,但这只能告诉我它是否支持2个,2-5个和5个以上的独立触摸,而不是确切的数字
答案 0 :(得分:0)
您可以从动作事件中获取指针数。
new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int pointersCount = event.getPointerCount()
}
}
关于可用触摸的最大数量,您可以通过PackageManager进行检查。
PackageManager packageManager = context.getPackageManager()
if (packageManager.hasSystemFeature(FEATURE_TOUCHSCREEN_MULTITOUCH)) {
//The device's supports basic two-finger gesture detection.
}
if (packageManager.hasSystemFeature(FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT)) {
//The device's capable of tracking two or more fingers fully independently.
}
if (packageManager.hasSystemFeature(FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND)) {
//The device's is capable of tracking a full hand of fingers fully independently.
//that is, 5 or more simultaneous independent pointers.
}