title: How to overlap imageviews in a layout
body: <p>I am facing an issue with the space between the views. Using a LinerLayout and dynamically adding views(ImageViews) to the linear layout. </p>
  
  <p>I want to adjust the space between the imageview. I want them to have an overlap - when a new view is added. </p>
  
  <p><a href="https://i.stack.imgur.com/1Vgsh.png" rel="nofollow noreferrer">Current view of the app</a> </p>
  
  <p>Currently a blue back ground is applied to highlight the two linear layouts. </p>
  
  <p>code to add Image view to the existing layout</p>
  
  <pre><code>dealerImages= (LinearLayout) findViewById(R.id.dealerImages);
      dealerImages.setBackgroundColor(Color.BLUE);
  
  ImageView view = new ImageView(BlackJack.this);
      view.setImageResource(R.drawable.back);
      dealerImages.addView(view);
  </code></pre>
  
  <p>Every time I add a new view - I want to specify the relative position to the old view. I want the <strong>new view to start from the center of the last view</strong> in the layout. </p>
  
  <p>Please let me know if you need any additional details. Please suggest if I need to use any other layout to make things easier.</p>
  
  <p>Edit - Posting the code here </p>
  
  <pre><code> playerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.MATCH_PARENT);
      dealerLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.MATCH_PARENT);
  
  
  private void dealTwoCardsEach(){
      player.addCard(hit());
      ImageView imageView = new ImageView(BlackJack.this);
      imageView.setImageResource(getResourceId(player.getFirstCard()));
      playerImages.addView(imageView, player.getCards().size()-1);
  
      dealer.addCard(hit());
      imageView = new ImageView(BlackJack.this);
      imageView.setImageResource(getResourceId(dealer.getFirstCard()));
      dealerImages.addView(imageView);
  
      player.addCard(hit());
      if(player.getCount() == 21)
          player.setBlackJack(true);
  
      imageView = new ImageView(BlackJack.this);
      imageView.setImageResource(getResourceId(player.getSecondCard()));
      updateMarginForPlayer(); // updating start margin
      playerImages.addView(imageView, player.getCards().size()-1, playerLayoutParams);
  
      dealer.addCard(hit());
  }
  
  
  private void updateMarginForPlayer(){
          playerLayoutParams.setMarginStart(playerLayoutParams.getMarginStart()+100);
  }
  </code></pre>
  
  <p>Please not i am not setting any margin for the first card for the player. 
  I can see both the cards until here. First Image with start margin of 0 and the second Image with start margin of 100.</p>
  
  <pre><code>private void handleHit(){
      Card c1 = hit();
      player.addCard(c1);
  
      ImageView imageView = new ImageView(this);
      imageView.setImageResource(getResourceId(c1));
      updateMarginForPlayer();
      playerImages.addView(imageView, playerLayoutParams);
  
  }
  </code></pre>
  
  <p>On click of the 'Hit' button is when handleHit() gets called. and the new images being added are making all the images from 2nd till the currrent view invisible. I can only see the first and last(latest added).</p>