title: Copy the rules of RelativeLayout.LayoutParams before API 19
body: <p>Im trying to copy <code>RelativeLayout.LayoutParams</code>, and i need the new Params to be exactly like the old ones. So consider this method:</p>
  
  <pre><code>private RelativeLayout.LayoutParams copyParams(RelativeLayout.LayoutParams source){
      RelativeLayout.LayoutParams copy = new RelativeLayout.LayoutParams((RelativeLayout.LayoutParams)source);
      return copy;
  }
  </code></pre>
  
  <p>Now, this works all right, but it will only compile above API-Level 19, as eclipse conveniently tells me.<br>
  To make this work pre-API-19, i tried this:</p>
  
  <pre><code>private RelativeLayout.LayoutParams copyParams(RelativeLayout.LayoutParams source){
      RelativeLayout.LayoutParams copy = new RelativeLayout.LayoutParams((ViewGroup.LayoutParams)source);
      copy.setMargins(source.leftMargin, source.topMargin, source.rightMargin, source.bottomMargin);
      return copy;
  }
  </code></pre>
  
  <p>By casting to ViewGroup.LayoutParams, i can force the use of the ViewGroup.LayoutParams CopyConstructor. It is readily available, but it will only copy the height and width. So i need to transfer the margins myself, which i do in line 3 of example 2. But this still leaves out the rules in the source layout, like <code>RelativeLayout.BELOW</code>, for example.  </p>
  
  <p>I can't find a <code>copyRules()</code> or <code>setRules()</code> method (or anything equivalent) anywhere in the docs, but i can see the <code>addRule()</code> method of <code>RelativeLayout.LayoutParams</code>. Considering that <code>source.getRules()</code> returns an Array i think i could loop over that and add each rule to my new LayoutParams, but that feels like im doing it wrong. Is there a sane way to copy these rules?</p>
  
  <p>TL;DR: Before API 19, is there a way to copy the rules of RelativeLayout.LayoutParams wholesale, and if not, what is the least insane way to copy them at all?</p>