title: Drawing line programmatically on a Layout
body: <p><a href="https://i.stack.imgur.com/M2x1I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M2x1I.png" alt="enter image description here"></a></p>
  
  <p>The red Margin represents an AbsoluteLayout, I have and arbitrary number of 'Board' objects placed on the screen. All I want is to draw a line on the screen using the coordinates of the Board object and the center of the screen. Each board object is responsible to draw this line.</p>
  
  <p>Also I want the line to be behind the Board objects I'm guessing I have to change the z-index, or maybe draw the line on the AbsoluteLayout?</p>
  
  <p>I have something like this:</p>
  
  <pre><code>public class Board {
  ImageView line;  //Imageview to draw line on
  Point displayCenter; //Coordinates to the center of the screen
  int x;
  int y;
  Activity activity;
  
  Board(Point p, Point c, Activity activity) // Point c is the coordinates of the Board object
  {   
      x = c.x
      y = c.y
      displayCenter.x = p.x;
      displayCenter.y = p.y;
      this.activity = activity;
  
      updateLine();
  }
  public void updateLine(){
      int w=activity.getWindowManager().getDefaultDisplay().getWidth();
      int h=activity.getWindowManager().getDefaultDisplay().getHeight();
  
      Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);
      line.setImageBitmap(bitmap);
  
      Paint paint = new Paint();
      paint.setColor(0xFF979797);
      paint.setStrokeWidth(10);
      int startx = this.x;
      int starty = this.y;
      int endx = displayCenter.x;
      int endy = displayCenter.y;
      canvas.drawLine(startx, starty, endx, endy, paint);
  }
  </code></pre>
  
  <p>}</p>