LoginSignup
16
19

More than 5 years have passed since last update.

[Android]複数ボタンの同時押し対処

Last updated at Posted at 2016-06-10

現在4択のクイズアプリを作成しているが、
ボタンを同時(Androidでは多少の誤差でも判別するため、厳密には違う)に2つ押された際に、意図しない挙動をしていることが分かった。

その事象は、
「その問題の判定には問題なかったが、次の問題の判定において、後に押された方の解答が適用される」
といったものだった。

アプリ開発初心者のため、ボタンが同時に押されることまで頭がまわらなかったので、
とりあえず検索した。

すると、簡単に制御できる方法があったので以下に記す。

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:splitMotionEvents="false">

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Button1" />

    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Button2" />
</RelativeLayout>

android:splitMotionEvents="false"の部分である。

ただし、同時に押されるであろうボタン群を、
android:splitMotionEvents="false"を適用したレイアウトに配置していないと効果がないようだ。

以上です。

16
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
19