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

前端 未结 7 1440
深忆病人
深忆病人 2021-01-01 14:15

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

相关标签:
7条回答
  • 2021-01-01 14:30

    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 ;)

    0 讨论(0)
  • 2021-01-01 14:34

    On your SlidingDrawer, override onTouch(View v, MotionEvent event) and return true.

    The one thing I am uncertain about is whether the framework will consider the drawer to overlay the View even when it is closed. If that is the case, then you should add some checks to see the state of the drawer, returning isOpened(), which will be true when the drawer is opened but false when it is closed.

    0 讨论(0)
  • 2021-01-01 14:35

    I was having the same problem. My items in the sliding drawer weren't able to gain focus. After trying several different things, I discovered that I had a placed in the sliding drawer between the tag and the Linear Layout that had the contentLayout.

    Once I removed it everything work fine.

    <SlidingDrawer ....>
        <FrameLayout android:id="@+id/slideHandle" ... />
    
            **MOVED** <ScrollView> **TO**
        <LinearLayout android:id="@+id/contentLayout" ... >
            <ScrollView> **HERE**
    

    I hope this helps someone.

    0 讨论(0)
  • 2021-01-01 14:41
    This is My main layout and where i introduce sliding drawer inside this. 
    
     <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Beige"
        android:clickable="true"
        android:orientation="vertical" >
    
        <Button
        android:id="@+id/DoneStart"
        android:layout_width="100dp"
        android:layout_height="40dp"
        android:textSize="14sp" />
    
        <SlidingDrawer
        android:id="@+id/SlidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:content="@+id/contentLayout"
        android:handle="@+id/handle_image"
        android:padding="1dp"
        android:rotation="180" >
    
        <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="8"
        android:text="Hello Slider" />
        </LinearLayout>
        </SlidingDrawer>
    

    Sample of mine after bit frustration where to add that android:clickable="true"

    0 讨论(0)
  • 2021-01-01 14:45

    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/>
    
    0 讨论(0)
  • 2021-01-01 14:45

    I think you should add a touch listener on slider and return true on it. In that way, you will tell to the system that the touch event has been consumed.

    0 讨论(0)
提交回复
热议问题