10

I'm trying to create a SlidingDrawer with LinearLayout content over a FrameLayout.

At first it all seems fine, I get my SlidingDrawer's handle at the bottom of the screen. But then, if I start dragging the handle up and the content starts showing, it gets clipped by the border rectangle of the handle. If I drag the handle all the way up the entire content eventually gets shown, however if I now drag the handle down, it will be clipped by the border rectangle of the content. Also, if the handle is all the way up, as soon as I start dragging it the whole content disappears.
I can still click on where the handle should be on the screen, drag it and the content would show, but I need to guess where the handle is.

What seems to be causing this is the fact that I have a SurfaceView in the xml file just before SlidingDrawer.
Removing the view from the xml solves this problem, however I need this view.

Here's the xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <!--  Removing this DrawView from here solves the problem -->
    <com.package.DrawView 
        android:id="@+id/main"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

    <SlidingDrawer  
        android:id="@+id/SlidingDrawer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:allowSingleTap="true"
        android:animateOnClick="true"
        android:handle="@+id/slideHandleButton"
        android:content="@+id/contentLayout" 
        android:padding="10dip">

        <Button
            android:id="@+id/slideHandleButton"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/sliding_button">
        </Button>

        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <Button 
                android:id="@+id/clearButton" 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Test">
            </Button>

        </LinearLayout>

    </SlidingDrawer>

</FrameLayout>   

Java:

package com.package;

import android.app.Activity;
import android.os.Bundle;

public class SlideTest extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
    }
}

package com.package;

import android.content.Context;
import android.util.AttributeSet;
import android.view.SurfaceView;

public class DrawView extends SurfaceView
{
    public DrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
}

Edit: I just noticed that if DrawView extends View and not SurfaceView this problem goes away. However, I'm using a dedicated drawing thread and according to the documentation (and LunarLander example) when using a dedicated drawing thread, it should draw to a SurfaceView.

Any help would be greatly appreciated!

ykrasik
  • 205
  • 3
  • 8

2 Answers2

14

android:background="#00000000"

Background color was the problem.

Naoonyoung
  • 156
  • 1
  • 3
  • Some clarification: Set this xml attribute on the SlidingDrawer element. – SilithCrowe Jul 11 '11 at 16:14
  • 1
    I don't think this actually solves the problem. The region where the drawer *would have been*, becomes blacked-over and the `SurfaceView` is not visible in that region even when the drawer is closed. I am still having the problem where the background is clipped by the location the handle would have occupied if the drawer were open. – Sanjay Manohar Feb 17 '12 at 03:13
  • This totally solved the problem for me, although I have no idea why. Thanks! – Louth Nov 14 '12 at 04:08
3

SurfaceView works by cutting a "hole" through the window to display another surface (the one you draw into.) This is what is causing the SlidingDrawer's drawer to be clipped. I'm sorry to say you won't be able to use both views together.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • 2
    I noticed that they basically have this feature in the HTC std camera app. Does this mean that they're doing the SlidingDrawer rendering directly in the SurfaceView or are they doing it all manually with OpenGL? – Weston Jun 23 '11 at 02:01
  • 1
    Adding the background color got it working on all devices I've tried. Before that it was working with some devices and not others. – Louth Nov 14 '12 at 04:14