Adding Views to another View
<p>Is there a possibility to add a view or derivative (button, textview, imageview etc...) to another view without having to go through layouts?</p>

<p>I have a class called ScreenView, it derives from View (e.g. public class ScreenView extends View).
I wanted to display text into it, labels, images etc..</p>

<p>On an iPhone it's trivial, simply create my objects and use addSubview method ; you can embed any UI objects into another. Most UI toolkits work that way too.</p>

<p>Problem with layouts is that I haven't found an easy way to properly position a subview (say a text view) in a given location of the enclosing View. I want one to contain the other...</p>

<p>I was hoping I had missed something in the documentation (which is far from being intuitive that's for sure) and I could do something like myView.addView(subview). But it ain't so :)</p>

<p>As a side question, what is the closest to iPhone's UILabel in the Android world?
A UILabel can contain a text or a graphic. Right now I've been using TextView and ImageView but they aren't anywhere as flexible when it comes to layout as a UILabel</p>

<p>Edit: Making my View inherit from ViewGoup instead, let me add subview..
However, I want to draw in my view. I found that when ScreenView extends ViewGroup, the onDraw function is never called then.</p>

<p>Something like:</p>

<pre><code>        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);

            // make the entire canvas yellow
            paint.setColor(Color.YELLOW);
            canvas.drawPaint(paint);
}
</code></pre>

<p>Would paint in yellow my view if ScreenView extends View ; but not if it extends ViewGroup.</p>

<p>How do you draw directly in the view then?</p>

<p>Thanks
JY</p>
