title: How to know if user tap on the screen
body: <p>When i tap on button app launches a <code>smaller view</code>, i need to close it if user taps any where on the screen except that opened view.</p>
  
  <p>I tried to add <code>TouchListener</code> to my parent layout, but its not detecting the click or touch event on the parent layout. </p>
  
  <pre><code>    &lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@drawable/home_bg"
              android:animateLayoutChanges="true"
              android:id="@+id/activity_profile"
              android:clickable="true"
              android:focusable="true"
              &gt;
  
              &lt;!-- VIEWS --&gt;
  
   &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>and in my activity i have written following code, but this is not working.</p>
  
  <pre><code>activity_profile.setOnTouchListener(object : View.OnTouchListener {
              override fun onTouch(v: View?, event: MotionEvent?): Boolean {
                  when (event?.action) {
                      MotionEvent.ACTION_DOWN -&gt; {
                          layoutContextual.visibility = View.GONE
                      }
                  }
  
                  return v?.onTouchEvent(event) ?: true
              }
          })
  </code></pre>