I have frame layout:
<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>
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?
EDIT:
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.
Is there an explanation for this behavior? Tnx!
Instead of using GestureListener you can override the onTouchListener in this way.
This will call longPress when the timer runs out and if an up comes in between it will cancel the LongPress
In my case I added flag to layoutParams of my view, which should have passed a touch event under:
This way view will ignore all touches (like view with visibility GONE)
To get the long clicks to pass through the widgetView
LinearLayout
addandroid:longClickable="true"
. (For ordinary clicks addandroid:clickable="true"
)So widgetView becomes:
Maybe setting the overlay's attribute
android:focusable="false"
orandroid:focusableInTouchMode="false"
would be enough.You could also make your own overlay widget and override its
onInterceptTouchEvent
method to return false always.Instead of setting a
GestureListener
on the top layout, you should create your own class that extendsLinearLayout
and to override it'sonTouchEvent
method. There you can implement the logic of long click \ short click etc.The click events will first be sent to the widget layout, and only if it doesn't handle them (hence it's
onTouchEvent
returnsfalse
), you will get them on the top layout.edit:
change the
com.example.touchtesting
to the name of your package. and this is the class: