안드로이드에서 버튼 두개를 동시 클릭을 방지하는 방법은 여러가지 존재한다.
이 방법중 가장 간단한 방법이 있다.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:splitMotionEvents="false"
>
<Button
android:layout_width="250dp"
android:layout_height="50dp"
android:text="버튼1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<Button
android:layout_width="250dp"
android:layout_height="50dp"
android:text="버튼2"
android:layout_marginTop="100dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
activity_main.xml
클릭 이벤트가 존재하는 뷰의 상위 레이아웃에 [ splitMotionEvents ] 속성 값을 [ false ] 를 주는 방법이다.
android:splitMotionEvents="false"
android:splitMotionEvents="true" :
뷰 그룹이 자식 뷰에게 동시에 발생하는 멀티터치 이벤트를 각각 분리해서 전달
사용자가 두 손가락으로 화면의 다른 두 지점을 동시에 탭할 경우, 이벤트가 각각의 지점에 대응하는 뷰로 분리되어 전달
android:splitMotionEvents="false" :
뷰 그룹이 멀티터치 이벤트를 분리하지 않고 하나의 이벤트로 처리
이는 일반적으로 뷰 그룹이 하나의 터치 입력만을 기대할 때 사용
'Mobile App Development > Android' 카테고리의 다른 글
[ Android ] 기종 별 사이즈 대응 (0) | 2024.04.09 |
---|---|
[ Android ] 로그캣 필터 쿼리 (0) | 2024.04.08 |
[ Android ] 안드로이드 줄 바꿈 처리 (0) | 2024.04.08 |
[ Android ] 안드로이드 구글 맵 내 위치 표시 (0) | 2022.02.13 |
[ Android ] 안드로이드 기본 환경 설정 (0) | 2022.02.12 |