2

My 1st layout is showing nothing. There is a 2nd layout above of it that is showing an image. How can I add a onTouchEvent to the 2nd layout? (I am asking this because OnTouchEvent just affects my 1st layout...) Its a relative layout overlaying another relative layout

Thank you very much.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/camera_layout"
    android:background="#000000">

    <RelativeLayout

        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/camera_preview"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="false"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="1dp"
        android:visibility="visible">


    </RelativeLayout>
 </RelativeLayout>
Aakash
  • 5,181
  • 5
  • 20
  • 37
Anderson
  • 111
  • 2
  • 8

1 Answers1

3

I did it doing this :

 final RelativeLayout rt = (RelativeLayout)findViewById(R.id.Test123);
    rt.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            Log.d("TOUCHED","PEWPEW");
            rt.onTouchEvent(arg1);
            return true;
        }
    });
}

My activity_main.xml is :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/camera_layout"
android:background="#000000">

<RelativeLayout

    android:orientation="horizontal"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:id="@+id/Test123"
    android:background="#2d2"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignWithParentIfMissing="false"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="1dp"
    android:visibility="visible"
    >
</RelativeLayout>

It will say D/TOUCHED﹕ PEWPEW every time you touch the Test123 RelativeLayout if you touch other it won't fire.

Skizo-ozᴉʞS ツ
  • 19,464
  • 18
  • 81
  • 148