title: After changing a property on a LayoutParams object, do I need to call setLayoutParams again?
body: <p>I have a View (containing an ad) that I need to scale to fit the screen width at a certain point in time (after the ad is loaded). So I have a method <code>setHeight(myView)</code> that calculates the correct height for the given screen width and changes the LayoutParams of the View accordingly. The crucial part of the code is this:</p>
  
  <pre><code>LayoutParams params = myView.getLayoutParams();
  int width = myView.getWidth();
  if (params != null &amp;&amp; width &gt; 0) {
      params.height = (int) Math.round(ratio * width);
  }
  </code></pre>
  
  <p>This seems to work for the most part, but sometimes the view is not scaled. It seems to only consistenly work if I add the following line at the bottom:</p>
  
  <pre><code>myView.setLayoutParams(params);
  </code></pre>
  
  <p>This seems to make sense, too, since Android Views call <code>requestLayout()</code> in their <code>setLayoutParams()</code> method. Conversely, I see no way how a change in a public field (<code>params.height</code>) would trigger a layout change.</p>
  
  <p>On the other hand, I repeatedly find tutorials on the net where the params are simply changed and then not set to the view again.</p>
  
  <p>So, my question is: Is it correct that, to immediately update the layout after changing a property of the LayoutParams, I need to call <code>setLayoutParams</code> again? And that simply changing the property will only lead to a layout change at some later point in time when the layout change is triggered from elsewhere?</p>