title: How to create imageviews dynamically on runtime?
body: <p>Im building an android app which needs to create max of 1-4 imageviews depending on the number of images i need to display on the screen. I have written a small code but it doesn't seem to divide the screen equally on to 4 imageviews though. The top 2 are a little larger than the bottom two in my case. Following is my code i really cant think what the issue is</p>
  
  <pre><code>private void CreateScreen()
  {
      int screenHeight = getWindowManager().getDefaultDisplay().getHeight();
      int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
  
      int matrixN = 2;
  
      int maxWForEachScreen = screenWidth / matrixN;
      int maxHForEachScreen = screenHeight / matrixN;
      RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayoutFullScreen);
  
      ImageView imgView1 = new ImageView(LiveViewer.this);
      ImageView imgView2 = new ImageView(LiveViewer.this);
      ImageView imgView3 = new ImageView(LiveViewer.this);
      ImageView imgView4 = new ImageView(LiveViewer.this);
  
      int size = 3;
  
      if(size &gt;= 3 &amp;&amp; size &lt;= 4)
      {
          imgView1.setImageResource(R.drawable.icon);
          imgView2.setImageResource(R.drawable.icon);
          imgView3.setImageResource(R.drawable.icon);
          imgView4.setImageResource(R.drawable.icon);
  
          RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(100, 100);
          RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(100, 100);
          RelativeLayout.LayoutParams params3 = new RelativeLayout.LayoutParams(100, 100);
          RelativeLayout.LayoutParams params4 = new RelativeLayout.LayoutParams(100, 100);
  
          params1.height = maxHForEachScreen/2;
          params1.width = maxWForEachScreen/2;
  
          params2.height = maxHForEachScreen/2;
          params2.width = maxWForEachScreen/2;
  
          params3.height = maxHForEachScreen/2;
          params3.width = maxWForEachScreen/2;
  
          params4.height = maxHForEachScreen/2;
          params4.width = maxWForEachScreen/2;
  
          params1.setMargins(0, 0, 0, 0);
          params2.setMargins(maxWForEachScreen/2, 0, 0, 0);
          params3.setMargins(0, maxHForEachScreen/2, 0, 0);
          params4.setMargins(maxWForEachScreen/2, maxHForEachScreen/2, 0, 0);
  
          relativeLayout.addView(imgView1, params1);
          relativeLayout.addView(imgView2, params2);
          relativeLayout.addView(imgView3, params3);
          relativeLayout.addView(imgView4, params4);      
      }
  }
  </code></pre>