【Java】Androidの同時押し出来ないようにする方法

Androidの場合、指定をしないとボタンの押下イベントをキャッチし
複数同時に押すことが出来てしまいます。


例えば、①のボタンを押下しながら②のボタンを押下すると
②のボタンの押下イベントが勝ちます。

 

 

 

 

 

 

 

その為、見た目的にも動作的にもあまりよくありません。

 

 

 

 

 

 

 

今回は、上記問題を解決する方法をまとめます。

※すごく簡単。

 

 

 

 

 

 

 

 


該当するresourceファイルのlayoutに以下指定を加えることで出来ます。

 


android:splitMotionEvents="false"

  


以下は例ソース
<test.xml

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:splitMotionEvents="false">

<ImageView
android:id="@+id/test_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>

<ImageView
android:id="@+id/test_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>

</LinearLayout>

 

 

 

 

 

 

 

 

 

複数layoutを指定している場合は、全てに付ける必要があります。

 

 

 

 

ただ、layout指定していないものはまた別に考える必要がありそう。。

 

 

 

 

 

 

 

 

 

 

以上です。