title: Setting layout parameters for an element inside a Gallery
body: <p>I am using a <code>Gallery</code> to display an horizontal timeline of events. Some of the events get <code>Gravity.TOP</code> and some <code>Gravity.BOTTOM</code> to align them above or below a nice line displaying the years. So far, so good.</p>
  
  <p>I want to change the left margin property of the elements in the top, so there are no huge gaps and the elements look interleaved. For example: setting a negative left margin to every element aligned on top.</p>
  
  <p>Each element of the <code>Gallery</code> consists on a <code>LinearLayout</code>, which can be set up a <code>MarginLayoutParams</code> instance to change the margins programatically. However, I'm getting a <code>ClassCastException</code> when using <code>MarginLayoutParams</code> inside the adapter because the Gallery code does this:</p>
  
  <pre><code>    // Respect layout params that are already in the view. Otherwise
      // make some up...
      Gallery.LayoutParams lp = (Gallery.LayoutParams) child.getLayoutParams();
  </code></pre>
  
  <p>Any ideas or hints on how to overcome this problem?</p>