我使用ProgressBar
作为自定义ListView
的一部分。现在,我想根据屏幕显示ProgressBar
的宽度,其值为ProgressBar
。
对于如果进度值是100,那么它应该显示其宽度为设备屏幕的100%,并且对于所有0-100值都应该如此。
我的代码如下:
layout.xml:根据进度值设置进度条的宽度并根据设备屏幕
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp" >
<ProgressBar
android:id="@+id/pbTopicAccuracy"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="20dp" />
<TextView
android:id="@+id/tvAccuracy"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/pbTopicAccuracy"
android:layout_alignLeft="@id/pbTopicAccuracy"
android:layout_alignTop="@id/pbTopicAccuracy"
android:paddingLeft="5dp"
android:textColor="@color/black"
android:textSize="12sp" />
</RelativeLayout>
Java代码:
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view.getId() == R.id.pbTopicAccuracy) {
int value = Integer.parseInt(data.toString());
((ProgressBar) view).setProgress(value);
view.setBackgroundResource(R.drawable.report);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(value, 30);
((ProgressBar) view).setLayoutParams(params);
}
}
});
它工作正常,但它不设置宽度按照它应该是。如果值为100,则它将宽度设置为像设备屏幕的4.5部分。
如何防止这个问题,并获得适当的宽度?
不,这是不同的东西。因为这个RelativeLayout是LinearLayout的父类。 –
你可以做你的问题的截图吗? –