title: Android - How do I position views in an offset relative to the center/top/bottom (etc.) of their parent?
body: <p>I have a <code>RelativeLayout</code> with views aligned relative to it (their parent), using (e.g.):</p>
  
  <pre><code>RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                  RelativeLayout.LayoutParams.WRAP_CONTENT);
  layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
  textView.setLayoutParams(layoutParams);
  </code></pre>
  
  <p>and now I wonder, how can I position the View relative to the bottom of its parent, but at an offset (e.g. 100 pixels above the bottom, 20 pixels from the left, etc.), or similarly with the center (30 pixels under the center)?</p>
  
  <p><img src="https://i.stack.imgur.com/rCEZr.png" alt="schematic image of the necessary layout"></p>
  
  <p>I've tried setting the margins of the View (e.g.): </p>
  
  <pre><code>layoutParams.setMargins(140, 0, 0, 0);
  </code></pre>
  
  <p>before applying it to the <code>textView</code>, but that didn't work.</p>
  
  <p>It seems like an extremely useful way to align views for various screen sizes.</p>
  
  <p>It's important for me to achieve this in code, without using xmls.</p>
  
  <p>Thanks!</p>