1

I've been looking on google on how to do this, from what I've gathered it's not as easy as 123 because the surface view will just draw above it, the solution which people have said is to use an xml layout and make a layout and then add the surface view as a child and the button as a child to that. However I'm completely lost on this I'd really love to see some code on how to do this (I prefer looking at examples and trial and error for learning).

My xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<FrameLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <Button
 android:id="@+id/Menu"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Menu" />
<Android.Game.GameView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"/>
</FrameLayout>
</LinearLayout>

I've got no code for adding in the button except for what you see on the xml (I've been doing a lot of trial and error).

project works like this: activity --> setContentView(surface view) --> render the gfx on the onDraw

Can someone please help me with this, once I've seen an example on how to do this with 1 object I'll be able to do it with other objects.

EDIT - solved it o.k I've managed to work it out from this post http://www.mail-archive.com/android-beginners@googlegroups.com/msg11780.html

I had to set the content view to the xml file, and add some constructs to the surface view so it would work

zidsal
  • 11
  • 1
  • 4

1 Answers1

0

I had to do something similar to display an ImageView over-top of a SurfaceView, and did it as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff">
    <com.my.package.DrawingCanvas
    android:id="@+id/canvas"
    android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:background="#ffffff" />
    <RelativeLayout
        android:id="@+id/toolbar_notification"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:gravity="center_vertical">
        <ImageView
            android:id="@+id/toolbar_notification_icon"
            android:layout_width="40dp"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:contentDescription="@string/content_desc_save_icon"
            android:gravity="center|center_vertical" />
    </RelativeLayout>
</RelativeLayout>

This results in the button floating over top of the SurfaceView on the bottom-right corner.

Unpossible
  • 10,607
  • 22
  • 75
  • 113