title: Multiple Child view in single Parent view
body: <p>i have made two view classes</p>
  
  <p>in first view class i am making more than one instance of second view</p>
  
  <p>and adding into first view but it displaying only one view</p>
  
  <p>please help me..</p>
  
  <p><strong>This is Parent View</strong> </p>
  
  <pre><code>package com.game.AntSmash;
  
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.drawable.Drawable;
  import android.view.SurfaceView;
  import android.widget.AbsoluteLayout;
  import android.widget.LinearLayout;
  
  public class surface extends LinearLayout {
  
  
      public surface(Context context) {
          super(context);
          this.setLayoutParams(new LinearLayout.LayoutParams(
                  LinearLayout.LayoutParams.FILL_PARENT,
                  LinearLayout.LayoutParams.FILL_PARENT));
          this.setBackgroundDrawable(getResources().getDrawable(R.drawable.grass));
          Drawable d = getResources().getDrawable(R.drawable.ant_big);
          d.setBounds(160, 0, 160 + d.getIntrinsicWidth(), d.getIntrinsicHeight());
          this.addView(new antView(context, d, 0.2f, 0, 0, 0, 0, 0));
          d = getResources().getDrawable(R.drawable.ant_big);
          d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
              this.addView(new antView(context, d, 0.2f, 0, 0, 160, 0, 0));
  
      }
  }
  </code></pre>
  
  <p><strong>This is child view</strong></p>
  
  <pre><code>package com.game.AntSmash;
  
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.graphics.Canvas;
  import android.graphics.Matrix;
  import android.graphics.Picture;
  import android.graphics.drawable.Drawable;
  import android.text.BoringLayout.Metrics;
  import android.view.View;
  import android.widget.ImageView;
  
  public class antView extends View {
      int screenW = 320;
      int screenH = 480;
      int X;
      int Y;
      int initialY ;
      int ballW;
      int ballH;
      int angle;
      float dY;
      float dX;
      float acc;
      int initialX;
      Drawable ball;
  
  
      public antView(Context context, Drawable bmp, float speed, int dx, int dy, int initialX, int initialY, int angle) {
          super(context); 
          this.ball = bmp;
          this.acc = speed;
          this.dX = dx;
          this.dY = dy;
          this.initialX = initialX;
          this.initialY = initialY;
          this.angle = angle;
      }
  
      @Override
      public void onDraw(Canvas canvas){
          super.onDraw(canvas); 
  
          //compute roughly ball speed and location
          Y+= (int) dY; //increase or decrease vertical position  
          if (Y &gt; (screenH - ballH)) {
              dY=(-1)*dY; //reverse speed when bottom hit 
          }
          dY+= acc; //increase or decrease speed
  
          //compute roughly ball speed and location
          X+= (int) dX; //increase or decrease vertical position  
          if (X &gt; (screenW - ballW)) {
              dX=(-1)*dX; //reverse speed when bottom hit 
          }
          dX+= acc / 5; //increase or decrease speed
  
  
          //increase rotating angle
          if ((angle = angle + 10) &gt;360) angle =0;
  
          //draw ball
          canvas.save(); //save the position of the canvas
          canvas.rotate(angle, X + (ballW / 2), Y + (ballH / 2)); //rotate the canvas
          canvas.translate(X, Y);
          ball.draw(canvas);
          canvas.restore(); //rotate the canvas back so that it looks like ball has rotated
  
  
          //call the next frame
          if(X &gt; screenW - ballW &amp;&amp; Y &gt; screenH - ballH) {
  
          } else {
              invalidate();
          }
  
      }
  
  }
  </code></pre>
  
  <p><strong>And this is activity</strong></p>
  
  <pre><code>package com.game.AntSmash;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.animation.TranslateAnimation;
  import android.widget.LinearLayout;
  
  public class AntSmashActivity extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          LinearLayout v = new surface(this);
          setContentView(v);
  
      }
  }
  </code></pre>