Sasan Farrokh Sasan Farrokh - 4 months ago 15
Java Question

android - button under a layout is still touchable

I have a layout with 5 buttons and each of them has a OnTouchListener that slides a frame layout on screen (on top of the buttons) but after that all of my 5 buttons is still touchable.


How to disable touch for views that is under other layouts such as
FrameLayout
that filled with a fragment ?


<Button
style="@style/tab_btn"
android:background="@drawable/village_button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_height="70dp"
android:layout_width="70dp"
android:text=""
android:onClick="buttonPress"/>

<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/sidebar_btn"
android:id="@+id/sidebar_btn4"
android:layout_marginTop="80dp"
android:layout_marginLeft="-18dp" />
<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/sidebar_btn"
android:id="@+id/sidebar_btn3"
android:layout_marginTop="120dp"
android:layout_marginLeft="-18dp" />
<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/sidebar_btn"
android:id="@+id/sidebar_btn2"
android:layout_marginTop="160dp"
android:layout_marginLeft="-18dp" />
<Button
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/sidebar_btn"
android:id="@+id/sidebar_btn"
android:layout_marginTop="200dp"
android:layout_marginLeft="-18dp" />
<FrameLayout
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_marginTop="-17dp"
android:layout_marginLeft="-176dp"
android:layout_marginBottom="-17dp"
android:id="@+id/sidebar"
android:background="@color/black">

</FrameLayout>

N J N J
Answer

I think you must add android:clickable="true" to FrameLayout

So it can capture the touch or click event when it's on above the button's

<FrameLayout
    android:layout_width="160dp"
    android:layout_height="match_parent"
    android:layout_marginTop="-17dp"
    android:layout_marginLeft="-176dp"
    android:layout_marginBottom="-17dp"
    android:id="@+id/sidebar"
    android:clickable="true"
    android:background="@color/black">