I am attempting to fix both the Width and the margins of a ProgressBar with layout params
The following correctly sets the layout_margin
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);
And this successfully sets the Layout_Width
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(finalWidth*2, 20);
progressBar.setLayoutParams(params);
However I cannot seem to combine the statement to get them to work together
Here is the layout xml
<RelativeLayout
android:id="@+id/relativelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/soundcloudimage" />
<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" />
<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" />
</RelativeLayout>
Any help would be great
EDIT: attempted the following
RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams)progressBar.getLayoutParams();
progressParams.width=finalWidth*2;
progressParams.height= 20;
progressParams.setMargins(0, 0, 0, finalHeight);
progressBar.setLayoutParams(progressParams);
and it results in this
EDIT: Also tried this:
RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(finalWidth*2, 20);
progressParams.setMargins(0, 0, 0, finalHeight);
progressBar.setLayoutParams(progressParams);
which creates this