5

I have both a SlidingDrawer and a custom SurfaceView that renders an image. I have just tried to drag the SlidingDrawer up and in doing so have discovered that it goes behind the image in the SurfaceView and is completely hidden.

As you can imagine this won't be much use to the user and therefore need the image to always fall behind the SlidingDrawer when it is pulled up. Is this possible?

Incase it helps this is the SlidingDrawer in the xml:

<SlidingDrawer
             android:id="@+id/drawer"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:handle="@+id/handle"
             android:content="@+id/content"
             android:layout_alignParentBottom="true">

             <TextView
                 android:id="@id/handle"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center"
                 android:paddingTop="5dip"
                 android:paddingBottom="5dip"
                 android:textStyle="bold"
                 android:text="text"/>


            <include layout="@layout/content"
                 android:id="@id/content"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"/>

         </SlidingDrawer>

And this is the SurfaceView in xml:

<FrameLayout android:id="@+id/FrameLayout01" 
        android:layout_width="fill_parent" android:layout_height="fill_parent">
        <com.android.imagemagic.widgets.ImageManipulationSurfaceView
        android:id="@+id/surfaceArea"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_gravity="center"/> 
    </FrameLayout>  

The SurfaceView is custom and uses the following code in the onDraw() method:

@Override
public void onDraw(Canvas canvas) { 
    super.onDraw(canvas);

    //Clear canvas
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    canvas.drawPaint(paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC));

    // Draw image
    canvas.drawBitmap(image, imageX, imageY, null);
}
Richard Lewin
  • 1,870
  • 1
  • 19
  • 26

3 Answers3

5

After much scanning around I have found the (simple) answer to my problem from the following Stack Overflow page: Android: SlidingDrawer disappears under SurfaceView. Quite simply in the SlidingDrawer xml element add:

android:background="#00000000";

Edit

Having reverted back to the my original code after implimenting the background it stopped working again. In the end I found where the other issue I had was that stopped the above solution from working. For everyone else’s benefit, ensure you don't set the SurfaceView z-index to the top via:

sv.setZOrderOnTop(true); 
Community
  • 1
  • 1
Richard Lewin
  • 1,870
  • 1
  • 19
  • 26
0

Even I faced the similar problem. But I found a workaround for this.
Just do slideHandleButton.setText(""); when the drawer is closed. This will make the button appear :)

Sunil
  • 856
  • 12
  • 24
0

Have you tried letting your super class draw last so that you draw below it?

@Override
public void onDraw(Canvas canvas) { 
    //Clear canvas
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
    canvas.drawPaint(paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC));

    // Draw image
    canvas.drawBitmap(image, imageX, imageY, null);

    super.onDraw(canvas);
}

An alernative to using a sliding draw is to have a button that start's a new activity, then you call overridependingtransition(int enterAnim, int exitAnim) before setContentView() to animate the activity to slide in and out.

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Blundell, many thanks for your reply. Tried moving the super.onDraw(canvas) as you suggested and it has made no difference i'm afraid. The alternative of using an activity is nice. I'll investigate that in due course. – Richard Lewin Jan 25 '12 at 22:39
  • Where is your XML file of the SlidingDrawer and the Surface? i.e. I hope it is , `` ? – Blundell Jan 25 '12 at 22:54
  • Blundell, the SlidingDrawer and Surface are in different layouts. The SlidingDrawer is in the main activity's layout while the Surface is in a layout used by a fragment that sits in the main activities layout. I'm using fragments. – Richard Lewin Jan 26 '12 at 09:48
  • So lets see the XML for the main layout with the drawer and the fragment, need to make sure your zIndexing is correct – Blundell Jan 26 '12 at 11:40