Hi,

I am new to the android developing world and have what I think is a
very simple question. I have created a circle on a canvas and drawn it
successfully. I now wish to add another circle to this already
existing canvas in a different position. I have defined my x and y as
arguments I pass to custom drawable view but when I try and get
another circle drawn it just replaces the one that was already
present. How do I keep the first circle and add on a second?

(My code below does not show trying to add another circle, it is
simply what works with creating a single colour circle).

Thanks

G




package com.image;

import android.app.Activity;
import android.os.Bundle;

public class image extends Activity {
    /** Called when the activity is first created. */

        private CustomDrawableView mCustomDrawableView;
        //private CustomDrawableView mCustomDrawableView2;

        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            //last argument 1 = green, all others = red
            mCustomDrawableView = new CustomDrawableView(this, 150, 40,
"green");
            setContentView(mCustomDrawableView);
        }
}

package com.image;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.view.View;



public class CustomDrawableView extends View {
    private ShapeDrawable mDrawable;

    public CustomDrawableView(Context context, int x, int y, String
Colour) {
        super(context);

        //int x = 80;
        //int y = 90;
        int width = 50;
        int height = 50;

        mDrawable = new ShapeDrawable(new OvalShape());
        if (Colour == "green"){
        mDrawable.getPaint().setColor(0xff74AC23);//green
        } else if (Colour == "red") {
        mDrawable.getPaint().setColor(0xffff0000);//red
        }
        mDrawable.setBounds(x, y, x + width, y + height);
    }

    protected void onDraw(Canvas canvas) {
        mDrawable.draw(canvas);
    }


}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to