SurfaceView dans la Mise en page

Alors j'ai fait beaucoup de recherche, mais ne peut toujours pas l'air de trouver la raison exacte pourquoi mon SurfaceView ne s'affiche pas. Voici un peu de fond sur ce que je fais:

J'ai un Linéaire de la Mise en page qui est placé Horizontalement. Il contient une ImageView, puis un vertical Linéaire de la Mise en page, et enfin un autre ImageView. Dans le Linéaire verticale de Mise en page, il y a trois choses sont essentielles: un autre ImageView en haut, une longue SurfaceView (appelé MagnetView) et une ImageView ci-dessous.

Voici le xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<!-- Left Magnetrak -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/vectorparts_01"
android:adjustViewBounds="true" />
<!-- Middle Linear Layout -->        
<LinearLayout 
android:layout_width="0dip"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="1">
<!-- Top Bar with Lifes and Score counter -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true">
<ImageView
android:adjustViewBounds="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/vectorparts_22"/>
<!-- Score counter -->
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="000000000000"
android:textColor="#000000" />
<!-- Life1 -->
<ImageView
android:id = "@+id/life1"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/vectorparts_13" 
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="1dp"
android:gravity="center" />
<!-- Life2 -->
<ImageView
android:id = "@+id/life2"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/vectorparts_13" 
android:layout_toRightOf="@id/life1"
android:layout_marginTop="1dp"
android:layout_marginLeft="1dp"
android:gravity="center" />
<!-- Life3 -->
<ImageView
android:id = "@+id/life3"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/vectorparts_13" 
android:layout_toRightOf="@id/life2"
android:layout_marginTop="1dp"
android:layout_marginLeft="1dp"
android:gravity="center" />
</RelativeLayout>
<!-- SurfaceView -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/middlesurface">
</LinearLayout>
<!-- Bottom Bar -->   
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"> 
<ImageView
android:adjustViewBounds="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/vectorparts_02"/>
</RelativeLayout>
</LinearLayout>
<!-- Right Magnetrak -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/vectorparts_01"
android:adjustViewBounds="true" />

Essentiellement, je veux le MagnetView de montrer à travers (ou percer un trou) où je l'ai mis dans la Mise en page. Mais il ne s'affiche pas. En fait, la seule fois de ma SurfaceView affiche est lorsque j'ai mis de l'activité setContentView() à la SurfaceView explicitement, l'annulation de tout le reste.

Ici est le fait de l'Activité:

public class Magnetraks extends Activity {
MagnetView midSurf;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
midSurf = new MagnetView(this);
LinearLayout midLL = new LinearLayout(this);
midLL.findViewById(R.id.middlesurface);
midLL.addView(midSurf);
setContentView(R.layout.main);
//Debugging purposes: run to see if middleSurface view is showing up when on its own.
//setContentView(midSurf);
}
@Override
protected void onResume() {
//TODO Auto-generated method stub
super.onResume();
midSurf.resume();
}
@Override
protected void onPause() {
//TODO Auto-generated method stub
super.onPause();
midSurf.pause();
}

Dois-je placer les SurfaceView en haut de ma mise en page xml? Il y a plus de attributs que je doit définir?
Puis-je juste recouvrir le SurfaceView plus de tout le reste, le rendre translucide et de dessiner ce dont j'ai besoin? Toute aide serait grandement apprécié, car je n'arrive pas à comprendre comment SurfaceViews travail. Il semble qu'ils sont en dehors de mon point de Vue de la hiérarchie, mais alors documentation m'ont dit qu'ils sont quelque chose de différent entièrement.

Merci.

MODIFIER 04/17/2012

Pour offrir un peu plus d'info:
Mon xml de l'INTERFACE utilisateur Concepteur montre une grande zone dans le milieu pour mon extension de SurfaceView classe, appelée MagnetView. Je l'ai déjà indiqué en rouge. (Stackoverflow ne me permet pas de poster des images encore)

Concepteur d'INTERFACE utilisateur(vue de http://24.media.tumblr.com/tumblr_m2mmqvBNwW1qcreoco1_500.jpg)
http://24.media.tumblr.com/tumblr_m2mmqvBNwW1qcreoco1_500.jpg

Voici la MagnetView (SurfaceView) classe:

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MagnetView extends SurfaceView implements Runnable, SurfaceHolder.Callback{
Thread mThread;
SurfaceHolder mSurfaceHolder;
volatile boolean running = false;
//Creates new surface view as well as a new surfaceholder, which allows access to the surface
public MagnetView (Context context){
super(context);
mSurfaceHolder = getHolder();
mSurfaceHolder.addCallback(this);
//this.setZOrderOnTop(true);
//getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
public void resume(){
running = true;
mThread = new Thread(this);
mThread.start();
}
public void pause(){
boolean retry = true;
running = false;
while(retry){
try {
mThread.join();
retry = false;
} catch (InterruptedException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void run() {
//TODO Auto-generated method stub
while(running){
if(mSurfaceHolder.getSurface().isValid()){
Canvas canvas = mSurfaceHolder.lockCanvas();
//... actual drawing on canvas
canvas.drawARGB(100, 255, 255, 80);
mSurfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
//TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
//TODO Auto-generated method stub
this.resume();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
//TODO Auto-generated method stub
}
}

OriginalL'auteur akappel | 2012-04-17