我正在尝试使用布局参数
来修复ProgressBar的宽度和边距以下正确设置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);
这成功设置了Layout_Width
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(finalWidth*2, 20);
progressBar.setLayoutParams(params);
但是我似乎无法将声明结合起来让他们一起工作
这是布局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>
任何帮助都会很棒
编辑:尝试以下
RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams)progressBar.getLayoutParams();
progressParams.width=finalWidth*2;
progressParams.height= 20;
progressParams.setMargins(0, 0, 0, finalHeight);
progressBar.setLayoutParams(progressParams);
,结果就是这个
编辑:也尝试了这个:
RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(finalWidth*2, 20);
progressParams.setMargins(0, 0, 0, finalHeight);
progressBar.setLayoutParams(progressParams);
创建此
答案 0 :(得分:1)
RelativeLayout.LayoutParams progressParams = (RelativeLayout.LayoutParams)progressBar.getLayoutParams();
progressParams.width=finalWidth*2;
progressParams.height= 20;
progressParams.setMargins(finalWidth, 0, finalWidth, finalHeight);
progressBar.setLayoutParams(progressParams);
修改强>
试试这个:
RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(finalWidth*2, 20);
progressParams.setMargins(0, 0, 0, finalHeight);
progressBar.setLayoutParams(progressParams);