Hi all,

I'm an Android newbie, and I'm trying to get started doing some simple
drawing on the screen. It looks like SurfaceView is the ticket for
this. I started with the SkeletonApp demo, removed all the UI
components, and put one custom SurfaceView at the top level, and in
that class, I overrode dispatchDraw() to do the actual drawing.
It appears to work -- the app builds and launches, and I can see my
dispatchDraw() getting called, but the screen stays black.
My custom view looks like this (edited a bit for brevity):

public class MyView extends SurfaceView {

        public Free42View(Context context) {
                super(context);
        }

        public Free42View(Context context, AttributeSet attrs) {
                super(context, attrs);
        }

        public Free42View(Context context, AttributeSet attrs, int defStyle)
{
                super(context, attrs, defStyle);
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
                Rect r = new Rect(50, 50, 100, 100);
                Paint p = new Paint();
                p.setColor(Color.WHITE);
                canvas.drawRect(r, p);
        }
}

The only other class in my project is the Activity; it doesn't do
anything interesting, other than calling setContentView() in its
onCreate() method.
My layout looks like this:

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

    <com.thomasokken.MyView android:id="@+id/canvas"
        android:layout_width="fill_parent"
android:layout_height="0dip"
        android:layout_weight="1" >
        <requestFocus />
    </com.thomasokken.MyView>

</LinearLayout>

Just out of curiosity, I tried making MyView a subclass of View
instead of SurfaceView, and overrode onDraw() instead of
dispatchDraw() -- the result was that the app crashes before any of my
code even gets the chance to execute. I have wandered into some
serious strangeness, even though what I'm trying to do seems so
trivial.
FWIW, I'm using Eclipse 3.4.2 with the Android plugin and SDK 1.5,
under Windows XP.
Can someone help me out?

Thanks,

 - Thomas

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to