スワイプ ジェスチャに応答するタッチ イベントをリニア レイアウトに追加したところ、うまく機能しました。ただし、レイアウトにボタンを追加すると、親ライナー レイアウトは無視されます。これを防ぐにはどうすればよいですか?
LinearLayout ln2 = (LinearLayout) findViewById(R.id.fr2);
ln2.setOnTouchListener(swipe);
使い方はonInterceptTouch
?
スワイプ ジェスチャに応答するタッチ イベントをリニア レイアウトに追加したところ、うまく機能しました。ただし、レイアウトにボタンを追加すると、親ライナー レイアウトは無視されます。これを防ぐにはどうすればよいですか?
LinearLayout ln2 = (LinearLayout) findViewById(R.id.fr2);
ln2.setOnTouchListener(swipe);
使い方はonInterceptTouch
?
独自のレイアウトを作成し、レイアウトの onInterceptTouchEvent(MotionEvent ev) メソッドをオーバーライドする必要があります。
たとえば、RelativeLayout を拡張する独自のレイアウトを作成しました
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return true; // With this i tell my layout to consume all the touch events from its childs
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Log.d(TAG, String.format("ACTION_DOWN | x:%s y:%s",
break;
case MotionEvent.ACTION_MOVE:
//Log.d(TAG, String.format("ACTION_MOVE | x:%s y:%s",
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
onInterceptTouchEvent
そして、レイアウトにボタンを配置すると、そのボタンをクリックしても、常に true が返されるため、レイアウトはすべての touchEvent を消費します。
これがあなたを助けることを願っています