title: Android. How to move the imageview(set position/margin) when it is created
body: <p>I want to put some images in an area at the application start.
  As the number of images is not a fixed amount, so I have to create images dynamically.
  I want to set the position/margin of every images while they're created for good balance.</p>
  
  <p>I have tried follows, but there is no efficacy.
  ・After Created, use imageview.layout().
  ・Use LayoutParams.margins().
  ・Use AsyncTask to set margins.
  ・activity.runOnUiThread().</p>
  
  <p>This is the code:</p>
  
  <pre><code>    // After access server, if needed then add a imageview to the 'c_box'
      // c_box: the parent that imageview to add.
      FrameLayout c_box = (FrameLayout) findViewById(R.id.c_box);
  
      MarginLayoutParams mlp = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  
      ImageView img1 = new ImageView(this);
      img1.setImageResource(R.drawable.c_file);
      img1.setLayoutParams(params);
      img1.setLongClickable(true);
      img1.setId(img_id);
      c_box.addView(img1);
  
      img1.setOnTouchListener(listener);
  
  
      **// it's possible to set the position by layout or margin?
      img1.layout(100, 100, 200, 200);**
  </code></pre>
  
  <p>I don't know where to call the invalidate() method.</p>
  
  <hr>
  
  <pre><code>// After access server, if needed then add a imageview to the 'c_box'
      // c_box: the parent that imageview to add.
      FrameLayout c_box = (FrameLayout) findViewById(R.id.c_box);
  
      MarginLayoutParams mlp = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      mlp.setMargins(100, 100, 200, 200);
      ImageView img1 = new ImageView(this);
      img1.setImageResource(R.drawable.c_file);
      img1.setLayoutParams(mlp);
      img1.setLongClickable(true);
      img1.setId(img_id);
      c_box.addView(img1);
  
      img1.setOnTouchListener(listener);
  </code></pre>