Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SlidingDrawer doesn't disable buttons 'under' the drawer

Tags:

This is the scenario: I have a button B, and a slidingdrawer that when pulled out covers the entire screen. When I pull out the screen, and touch the screen where B used to be visible, its action is still executed.

How can I get around this?

I found this thread describing the very same problem, but no answer was accepted and the ones given I didn't manage to get working.

UPDATE: I have a file named Report.java, with a corresponding report.xml file as seen below.

    <SlidingDrawer
     android:id="@+id/drawer"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:handle="@+id/reportSlideButton"
     android:content="@+id/reportContent"
     android:orientation="horizontal">

    <LinearLayout 
        android:id="@id/reportContent" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:layout_weight="1"
        android:padding="10dp"
        android:background="@color/bg_color">
            <TextView android:id="@+id/garbageTypeTextView" 
                android:layout_height="wrap_content" 
                android:textColor="@color/text" 
                android:layout_width="fill_parent" 
                android:text="@string/garbageTypeString" 
                android:textStyle="bold"/>
            <Spinner android:id="@+id/garbageTypeSpinner"
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent"/>
            <TextView android:id="@+id/textViewForDateTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" 
                android:text="@string/dateString"
                android:textColor="@color/text" 
                android:textStyle="bold" />
            <TextView android:id="@+id/dateTextView"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textColor="@color/text" />
            <TextView android:id="@+id/textViewForAddressTitle"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:text="@string/addressString"
                android:textColor="@color/text" 
                android:textStyle="bold" />
            <TextView android:id="@+id/addressTextView"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textColor="@color/text" />
            <TextView  android:id="@+id/textViewForPositionTitle"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" 
                android:text="@string/positionString"
                android:textColor="@color/text" 
                android:textStyle="bold" />
            <TextView android:id="@+id/positionTextView"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:textColor="@color/text" />
            <TextView android:id="@+id/textViewForCommentTitle"
                android:layout_height="wrap_content" 
                android:layout_width="wrap_content" 
                android:text="@string/commentString"
                android:textColor="@color/text" 
                android:textStyle="bold" />
            <EditText android:id="@+id/commentTextBox"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent" 
                android:layout_weight="1"/>
            <Button android:id="@+id/sendCrapportButton" 
                android:onClick="sendCrapport"
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent"
                android:text="Skicka rapport" />

    </LinearLayout>
        <Button android:id="@id/reportSlideButton"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:text=">"/>
</SlidingDrawer>

Adding components:

protected void addComponents() {
    takePictureButton = (ImageButton) findViewById(R.id.takePictureButton);
    slidingDrawer = (SlidingDrawer) findViewById(R.id.drawer);
}
like image 637
Soroush Hakami Avatar asked Mar 22 '11 15:03

Soroush Hakami


2 Answers

you could add android:clickable="true" to your slider content tag (id reportContent). that way it won't "click through". your buttons inside the slider should still work.. i hope ;)

like image 84
F. Horn Avatar answered Nov 11 '22 12:11

F. Horn


Just adding to @f-horn 's answer:

If you include a layout from a different file (like I do) for the SlidingDrawer, you have to put the 'android:clickable="true"' in the included layout file, not in the include tag. Let me rather use an example:

This will not work:

main.xml

<SlidingDrawer  android:handle="@+id/handle"
       android:content="@+id/content">

        <ImageView android:id="@id/handle" />
        <include android:id="@+id/content" layout="@layout/some_other_layout" 
        android:clickable="true"/>
</SlidingDrawer>'

This will:

main.xml

<SlidingDrawer  android:handle="@+id/handle"
        android:content="@+id/content">

        <ImageView android:id="@id/handle" />
        <include android:id="@+id/content" layout="@layout/some_other_layout"/>
</SlidingDrawer>'

some_other_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:clickable="true"> ............
<LinearLayout/>
like image 29
RichardB Avatar answered Nov 11 '22 10:11

RichardB