android - overdraw layout allows touch through LinearLayout

dropsOfJupiter picture dropsOfJupiter · Apr 12, 2012 · Viewed 18.3k times · Source

in the following UI I have this below drabable overlaying the entire screen. The LinearLayout is transparent and allows controls below it to be clickable or touchable. Basically I can scroll a list below this LinearLayout as well as click controls. How do I disable that?

See attached example.enter image description here

Thank you

<RelativeLayout
     xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/rlExtNavbar" 
    android:orientation="vertical"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:gravity="fill_vertical"
    android:layout_gravity="fill_vertical"
    android:background="@color/transparent" xmlns:tools="http://schemas.android.com/tools" tools:ignore="Overdraw">
    <RelativeLayout
        android:id="@+id/expandedNavbarLayout" 
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" >
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/transparentLayout" 
        android:orientation="vertical"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content"
        android:layout_below="@id/expandedNavbarLayout"
        android:focusableInTouchMode="false"
        android:focusable="false"
        android:background="@color/fulltransparent">
    </LinearLayout>

</RelativeLayout>

Answer

Theo picture Theo · Apr 22, 2012

Just setting the android:clickable="true" property for the LinearLayout in the XML will prevent the clicks going through -- no need for a click listener.