1

たとえば、次のようなRelativeLayoutがあります。

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

    <LinearLayout
        android:id="@+id/A"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <LinearLayout
        android:id="@+id/B"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout >

では、Bにタッチしても、Bがそのタッチイベントを処理しない場合、タッチイベントが子Aに渡されるのをどのように回避できますか?

4

1 に答える 1

0

常にタッチイベントを消費するビューBのタッチリスナーを設定できるため、Aはタッチイベントを取得しません。

コード例:

mA = (LinearLayout) getView().findViewById(R.id.A);
    mA.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Toast.makeText(getActivity(), "Touch A",Toast.LENGTH_LONG).show();
            return false;
        }
    });
    mB = (LinearLayout) getView().findViewById(R.id.B);
    mB.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Toast.makeText(getActivity(), "Touch B",Toast.LENGTH_LONG).show();
            return true;
        }
    });
于 2012-10-19T06:38:18.443 に答える