title: Android combining two LayoutParams
body: <p>I am attempting to fix both the Width and the margins of a ProgressBar with layout params</p>
  
  <p>The following correctly sets the layout_margin</p>
  
  <pre><code>int finalHeight = soundcloudImage.getHeight() / 8;
  int finalWidth = soundcloudImage.getWidth() / 4;
  
  RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams)progressBar.getLayoutParams();
  
  progressParams.setMargins(0, 0, 0, finalHeight);
  
  progressBar.setLayoutParams(progressParams);
  </code></pre>
  
  <p>And this successfully sets the Layout_Width</p>
  
  <pre><code>RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(finalWidth*2, 20);
  
  progressBar.setLayoutParams(params);
  </code></pre>
  
  <p>However I cannot seem to combine the statement to get them to work together</p>
  
  <p>Here is the layout xml</p>
  
  <pre><code>&lt;RelativeLayout
                  android:id="@+id/relativelayout"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" &gt;
  
                  &lt;ImageView
                      android:id="@+id/imageView"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:src="@drawable/soundcloudimage" /&gt;
  
                  &lt;TextView
                      android:id="@+id/myImageViewText"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_alignBottom="@+id/imageView"
                      android:textSize="20dp"
                      android:layout_centerHorizontal="true"
                      android:text=""
                      android:textColor="#EA4F17" /&gt;
  
                  &lt;ProgressBar
                      android:id="@+id/progressBar"
                      style="?android:attr/progressBarStyleHorizontal"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_alignBottom="@+id/imageView"
                      android:layout_alignLeft="@+id/imageView"
                      android:layout_alignParentRight="true" /&gt;
  
              &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Any help would be great</p>
  
  <p><strong>EDIT:</strong> attempted the following </p>
  
  <pre><code>RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams)progressBar.getLayoutParams();
  progressParams.width=finalWidth*2;
  progressParams.height= 20;
  progressParams.setMargins(0, 0, 0, finalHeight);
  
  progressBar.setLayoutParams(progressParams);
  </code></pre>
  
  <p>and it results in this</p>
  
  <p><img src="https://i.stack.imgur.com/Zjlx1.png" alt="enter image description here"></p>
  
  <p><strong>EDIT:</strong> Also tried this:</p>
  
  <pre><code>RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(finalWidth*2, 20);
  progressParams.setMargins(0, 0, 0, finalHeight);    
  progressBar.setLayoutParams(progressParams);
  </code></pre>
  
  <p>which creates this<img src="https://i.stack.imgur.com/5jxTu.png" alt="enter image description here"></p>