1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

problem drawing inside view


Last Updated:

  1. darkdusky

    darkdusky New Member This Topic's Starter

    Joined:
    Jan 27, 2010
    Messages:
    2
    Likes Received:
    0
    I am trying to learn building apps for the android.

    I have a few TextViews etc and a small view in the top left corner into which I can draw shapes. I have placed the buttons, view etc on main screen using xml (DroidDraw). All these show and work fine. I used the following to display them:
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    Is it possible to draw directly into this xml view? I have managed to change its background colour but cannot draw into it.
    Since I couldn't draw inside the xml view I tried using the extend View approach.
    E.g.
    public class DrawView extends View {
    private Paint paint;
    public DrawView(Context context) {
    super(context);
    paint = new Paint();
    ......
    I can activate this by using:

    newgame.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    CreateView();
    setContentView(gV);
    }
    });
    }


    public void CreateView()
    {
    gV = new DrawView(this);
    }



    This creates a new view which fills the screen and paints correctly etc, but it hides all the buttons of main screen.

    I don't mind which method I get to work but I need either:
    1. how do I draw inside a view built inside main.xml;
    or
    2.how do I display a View created class DrawClass inside the main screen without covering any controls in the main.xml. i.e is there an alternative to setContentView(gV); which will insert a view into one section of screen?
     

    Advertisement
  2. DKDiveDude

    DKDiveDude New Member

    Joined:
    Dec 30, 2010
    Messages:
    2
    Likes Received:
    0
    I am just starting out with Java and Android programming, and I can't believe the trouble I have finding out how to draw [with code] to a View layout created in main.xml as they promote this way of setting up layout's.

    Anyone please throw me a freaking bone, thanks! :D
     

Share This Page

Loading...