Problem mit SurfaceView

K

ko5tik

Stammgast
41
Hallo Allle,

Irgendwie komme ich nicht weiter. Ich habe einen SurfaceView und versuche darauf zu Malen.

So deklariere ich es (workarea):
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent">

    <LinearLayout android:id="@+id/overlay"
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
            >



        <!-- display processing result -->
        <SurfaceView android:id="@+id/workarea"
                   android:layout_width="fill_parent"
                   android:layout_height="80dp"
                   android:layout_gravity="center"           
                   android:background="#ff00ff00"    
             ></SurfaceView>

        <FrameLayout android:layout_width="fill_parent"
                     android:layout_height="fill_parent"
                     android:background="#00000000"
                >

            <ImageView
                    android:id="@+id/scanarea"
                    android:layout_width="fill_parent"
                    android:layout_height="80dp"
                    android:src="@drawable/scanarea"
                    android:paddingLeft="5dp"
                    android:paddingRight="5dp"
                    android:layout_gravity="center"
                    >
            </ImageView>

        </FrameLayout>

    </LinearLayout>
</FrameLayout>

Und initialisiere es mit Callback im OnCreate:

Code:
        final SurfaceView workAreaView = (SurfaceView) findViewById(R.id.workarea);

        workArea = workAreaView.getHolder();
        workArea.addCallback(this);
        workArea.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);

Dann mache ich von meinen Thread aus:
Code:
                Canvas c = null;
                try {
                    System.err.println("locking canvas");
                    c = workArea.lockCanvas();
                    if (c != null) {
                        System.err.println("canvas:" + c.isOpaque());
                        // synchronized (mSurfaceHolder) {
                        // c.drawBitmap(backBuffer, 0, 0, paint);
                        c.drawARGB(255,255,0,0);
                        System.err.println("**************** drawn rect");
                    } else {
                        System.err.println("surface not ready");
                    }

                    // }
                } finally {
                    // do this in a finally so that if an exception is thrown
                    // during the above, we don't leave the Surface in an
                    // inconsistent state
                    if (c != null) {
                        workArea.unlockCanvasAndPost(c);
                        System.err.println("********** unlocked and posted");
                    }
                }


Und als Ergebnis sehe ich nur den Grünen Hintergrund, und nicht die rote Fläche. Was mache ich dabei falsh?

( in meinen Colors Spiel mache ich auch nichts anderes, nur dort ist der SurfaceView im Vollbild )
 

Ähnliche Themen

S
Antworten
4
Aufrufe
995
Sempervivum
S
B
Antworten
4
Aufrufe
490
bb321
B
R
Antworten
3
Aufrufe
1.625
Ritartet
R
Zurück
Oben Unten