通过视图android传递click事件 [英] Pass click event through the view android
问题描述
我有框架布局:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" >
<LinearLayout
android:id="@+id/widgetView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:gravity="center" >
</LinearLayout>
<LinearLayout
android:id="@+id/widgetOverlayFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false" >
</LinearLayout>
第一个布局包含小部件布局,第二个是透明的,并接受onLongClick作为拖动方法。这是可行的,问题是当我想与小部件进行交互,单击某些东西时,clickEvent由overlayFrame承担。如何将点击事件通过overlayFrame传递给widgetView?
First layout contains widget layout, and second one is transparent and receives onLongClick for dragging method.That works, the problem is when i want to interact with widget, to click something, click event is taken by overlayFrame. How can i pass click event trough overlayFrame to widgetView?
编辑:
现在我正在尝试附加将GestureLister更改为overlayFrame LinearLayout,以某种方式查看表示单击和单击的MotionEvent之间的区别。我面临的问题是手势侦听器中的OnLongPress总是被称为单击操作或长按。
Now I'm trying to attach GestureLister to overlayFrame LinearLayout, to somehow see difference between MotionEvent that represent single click and long click. The problem that I'm facing is that OnLongPress in gesture listener is always called whatever I do, single click or long click.
此行为是否有解释? Tnx!
Is there an explanation for this behavior? Tnx!
推荐答案
可以使用这种方式覆盖onTouchListener,而不是使用GestureListener。
Instead of using GestureListener you can override the onTouchListener in this way.
当计时器用尽时,它将调用longPress;如果在两次间隔之间加起,则将取消LongPress
This will call longPress when the timer runs out and if an up comes in between it will cancel the LongPress
CountDownTimer c;
long time=5000;
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
c= new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
time=millisUntilFinished;
}
public void onFinish() {
Log.i("","LONG PRESS");
}}.start();
break;
case MotionEvent.ACTION_UP:
if (time>0) {
Log.i("example","short click");
c.cancel();
}
break;
}
return true;
}
这篇关于通过视图android传递click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!