Hi, all!

How can I draw the content of ViewGroup in SurfaceView? I don't see
anything at screen. I use the extended class AbsoluteLayout from
ViewGroup. My pseudo code likes this:

...
class SomeView extends View {

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

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
                setMeasuredDimension(34, 34);
        }

        @Override
        protected void onDraw(Canvas canvas) {
                super.onDraw(canvas);
                Paint paint = new Paint();
                paint.setColor(Color.RED);
                canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
        }
}

...
AbsoluteLayout layout = new AbsoluteLayout(context);
layout.addView(new SomeView(context), new AbsoluteLayout.LayoutParams
(35,35, 100,100));

...
  SurfaceHolder holder = surface.getHolder();
...
        // In some thread with SurfaceHolder I do:
        public void run() {
                while (running) {

                        Canvas canvas = null;
                        try {
                                canvas = holder.lockCanvas(null);
                                synchronized (holder) {
                                        layout.draw(canvas);
                                }
                        } finally {
                                if (canvas != null) {
                                        holder.unlockCanvasAndPost(canvas);
                                }
                        }
                }
        }
...

I don't understand why this code don't show anything.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
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