I am designing an Android application and I would like to find a way to handle multitouch between multiple nested views.
My layout is as following:
Relative layout
|
|---Linear layout
| \---Linear layout
| \--Button A
|
|---Linear layout
\---Button B
The two buttons take approximately 50% of the screen size. I would like to be able to press the two buttons at the same time one after the other. I can press button B and then A but when I press A, I'm not able to press B.
It seems that it's a normal behaviour if we consider the way that Android handles event. I googled my problem and I only found complex solutions that involve rewriting a custom view and the "DispatchTouchEvent" method.
Do you know if there's a easy way to avoid that behaviour (being able to press A then B and B and then A)?
I wrote a minimal example: run an activity with the following layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:splitMotionEvents="true"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="epl.groupe16.testbutton.MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="New Button"
android:id="@+id/button" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:weightSum="2">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:id="@+id/button21"
/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="New Button"
android:id="@+id/button20"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
I can press the lowest button, hold my touch and then click on the upper button but if I try the highest first, the lowest isn't clickable.
Thank you in advance