草庐IT

MotionEvent

全部标签

Android MotionEvent压力测量单位

我正在使用MotionEvent实例中的getPressure(index)方法来获取应用于屏幕的压力值。我正在尝试弄清楚如何将该值至少转换为标准测量单位的近似值。在Android中,压力值是一个介于0到1之间的float。我需要以某种方式用牛顿来表示它。据我了解,这在不同设备上是不同的,因此不可能获得真正精确的单位测量值,但我可以接受近似值。比如手写笔在全力触摸屏幕时多少牛顿是正常的(设备测量1.0f的压力) 最佳答案 我认为你只能猜测,并且知道结果会受到巨大不确定性的影响。我看到的解决方案:在屏幕上放置一个已知重量的合适物体。不

android - 在不消耗 MotionEvent 的情况下处理 Android 中的滑动/滚动

我的应用程序的屏幕一侧有一个ViewFlipper,其中包含一堆不同的View,我希望用户能够通过向左滑动来关闭它。所以我做了通常的...privateclassSwipeDetectorextendsSimpleOnGestureListener{@OverridepublicbooleanonFling(MotionEvente1,MotionEvente2,floatvelocityX,floatvelocityY){//Dismissview}@OverridepublicbooleanonDown(MotionEvente){returntrue;}}...然后设置ViewF

android - 查明 MotionEvent 何时结束

我试图弄清楚如何查看MotionEvent何时完成某个事件(即,用户按下屏幕,四处拖动,然后将手指从屏幕上移开)。在文档中,我只看到getEventTime在事件开始时生成,但没有提及如何确定事件何时结束。有什么想法吗? 最佳答案 有MotionEvent.ACTION_UP和MotionEvent.ACTION_DOWN标志您可以通过将其与event.getAction()进行比较来检查你可以这样使用@OverridepublicbooleanonTouch(Viewv,MotionEventevent){switch(event

android - MotionEvent.ACTION_DOWN 没有被调用,即使我为它返回 true

我的ListView的LinearLayout有一个onTouchListener,我正在尝试使用ACTION_DOWN和ACTION_UP数据,用于检测用户何时滑动到下一个ListView。但是,MotionEvent永远不会等于ACTION_DOWN,尽管ACTION_UP工作得很好。经过大量谷歌搜索后,我能找到的唯一解决方案是在调用事件时返回true,但我已经在这样做了。这是我的onTouchListener代码View.OnTouchListenermTouchListener=newView.OnTouchListener(){@Overridepublicbooleanon

android - 在 onTouchEvent() 中的 MotionEvent.ACTION_MOVE 期间重绘 View

我已经创建了我自己的扩展RelativeLayout的组件,在它里面我有一个View类型的字段,它是用边距定位的:蓝色四边形代表我的父View,红色圆圈是subview。现在我想让用户在屏幕上移动手指的同时移动这个红色圆圈。这是我的onTouchEvent()方法:@OverridepublicbooleanonTouchEvent(MotionEventevent){inteventAction=event.getAction();switch(eventAction){caseMotionEvent.ACTION_DOWN://fingertouchesthescreenbreak

android - Android 中的 MotionEvent.ACTION_DOWN 过于敏感。即使只是触摸屏幕片刻,也会收到此事件

我有一个布局(一个表格布局)。每当用户执行“向下”手势时,都需要调用特定函数。但是,ontouchlistener会立即捕获事件,而不是等到用户执行正确的“下拉”手势。我的代码是:homePageTableLayout.setOnTouchListener(newView.OnTouchListener(){publicbooleanonTouch(Viewview,MotionEventevent){if((event.getAction()==MotionEvent.ACTION_DOWN)){startSyncData();}returntrue;}});目前,正在发生的是立即调

java - 不显示 MotionEvent.ACTION_UP 或 MotionEvent.ACTION_CANCEL

我正在编写一个需要响应触摸事件的Android应用程序。我希望我的应用程序将列表项的颜色更改为自定义颜色。我编写了以下代码,但只有MotionEvent.ACTION_DOWN部分有效。LogCat显示ACTION_CANCEL和ACTION_UP根本没有被调用。您能否帮我理解为什么我的代码无法正常工作。这是我的代码...view.setOnTouchListener(newOnTouchListener(){publicbooleanonTouch(Viewv,MotionEventevent){if(event.getAction()==MotionEvent.ACTION_UP)

android - 如何检测 Android 服务中的 MotionEvent.ACTION_DOWN

我正在运行后台服务来检测Android5.0中的MotionEvent.ACTION_DOWN。我使用了下面的代码,它可以检测到我的触摸事件,但我无法触摸其他应用程序。我该如何解决?如果你有更好的解决方案,请给我。谢谢大家。publicclassTouchServiceListenerextendsServiceimplementsOnTouchListener{privateWindowManagermWindowManager;//linearlayoutwillusetodetecttoucheventprivateLinearLayouttouchLayout;@Overrid

android - 如何在 android 中模拟 MotionEvent 和 SensorEvent 进行单元测试?

如何对androidSensorEvent和MotionEvent类进行单元测试?我需要为单元测试创​​建一个MotionEvent对象。(我们有MotionEvent的obtain方法,我们可以在模拟后使用它来创建MotionEvent自定义对象)对于MotionEvent类,我尝试使用Mockito,例如:MotionEventMotionevent=Mockito.mock(MotionEvent.class);但是我在AndroidStudio上遇到以下错误:java.lang.RuntimeException:Methodobtaininandroid.view.Motion

android - 如何找到 MotionEvent ACTION_CANCEL 的源 View

如何找到导致MotionEventACTION_CANCEL的View?我有一个正在接收ACTION_CANCEL的View“A”,我不希望这种情况发生。在某处,View“B”正在“消耗”MotionEvent。我希望有一种方法可以找出谁是“B”,这样我就可以解决这个问题。我已尝试查看我的代码以查找各种OnTouchEvent()和OnInterceptTouchEvent()处理程序,但尚未找到罪魁祸首。我还在有问题的ACTION_CANCEL处设置了一个断点,但我无法识别MotionEvent中可能代表“B”的任何内容。 最佳答案