我在幾個ImageButtons和代碼實現自來水事件的其他觸摸事件看起來是這樣的觸地的佈局阻止按鈕
MyTouchListener touchListener = new MyTouchListener();
l1.setOnTouchListener(touchListener);
r1.setOnTouchListener(touchListener);
l2.setOnTouchListener(touchListener);
r2.setOnTouchListener(touchListener);
public class MyTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
switch (v.getId()) {
case R.id.l1:
clickL1(v);
break;
case R.id.r1:
clickR1(v);
break;
case R.id.l2:
clickL2(v);
break;
case R.id.r2:
clickR2(v);
break;
}
return true;
}
return false;
}
我所遇到的問題是,當我在佈局(按住一個手指的任何地方除外圖像按鈕),當我按住按鈕時,按鈕不會註冊任何事件。
我試圖給我的佈局自己的觸摸偵聽器返回false,但沒有奏效。
我該怎麼做才能「忽略」佈局上的觸碰事件,並且只需要正常聽取imagebutton事件?
<?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:id="@+id/relativeLayout"
android:splitMotionEvents="true"
tools:context="com.example.josip.something.GameOffline">
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/l1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:focusableInTouchMode="true"/>
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/r1"
android:layout_above="@+id/l1"
android:layout_toRightOf="@+id/l1"
android:layout_toEndOf="@+id/l1"
android:focusableInTouchMode="true"/>
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/r2"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:focusableInTouchMode="true"/>
<ImageButton
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/l2"
android:layout_above="@+id/r2"
android:layout_toLeftOf="@+id/r2"
android:layout_toStartOf="@+id/r2"
android:focusableInTouchMode="true"/>
<RelativeLayout>
請將您的xml –
@KirillK在那裏:) – user6754277