问题使用ProgressBar.setProgressDrawable [英] Issue with using ProgressBar.setProgressDrawable
问题描述
使用 setProgressDrawable
为进度
自定义颜色以正确的方式对我们不起作用。我们在的ListView
的行使用progressbars,但如果在列表中有多个元素只显示进度。如果一个元素的进度是空的。
CursorAdapter.java:
公共类CursorAdapter的扩展SimpleCursorAdapter {
公众的CursorAdapter(上下文的背景下,INT布局,光标C,的String []而成,
INT []键){
超(背景下,布局,C,从,到);
}
公共无效bindView(查看视图,上下文的背景下,光标光标){
super.bindView(查看,背景,光标);
updateProgressbar(查看,光标);
}
/ **
*此方法更新使用numberpages和进度
*当前页的价值观。
* /
私人无效updateProgressbar(查看视图,光标光标){
进度进度=(进度)视图
.findViewById(R.id.progressbarHorizontal);
progressBar.setProgressDrawable(view.getResources()。getDrawable(
R.drawable.greenprogress));
progressBar.setMax(cursor.getInt(cursor.getColumnIndex(numberpages)));
progressBar.setProgress(cursor.getInt(光标
.getColumnIndex(当前页)));
}
}
/res/drawable/greenprogress.xml:
< XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目机器人:ID =@机器人:ID /背景>
<形状>
<边角机器人:半径=5dip/>
<梯度
机器人:startColor =#ff9d9e9d
机器人:centerColor =#ff5a5d5a
机器人:centerY =0.75
机器人:endColor =#ff747674
机器人:角=270
/>
< /形状>
< /项目>
<项目机器人:ID =@机器人:ID / secondaryProgress>
<夹>
<形状>
<边角机器人:半径=5dip/>
<梯度
机器人:startColor =#80ffd300
机器人:centerColor =#80ffb600
机器人:centerY =0.75
机器人:endColor =#a0ffcb00
机器人:角=270
/>
< /形状>
< /剪辑>
< /项目>
<项目机器人:ID =@机器人:ID /进步>
<夹>
<形状>
<角落
机器人:半径=5dip/>
<梯度
机器人:startColor =#33FF33
机器人:endColor =#008000
机器人:角=270/>
< /形状>
< /剪辑>
< /项目>
< /层列表>
有什么不对的code,为什么它的工作原理只是,如果有列表中的一个以上的元素呢?如果没有设置自定义进度条样式一切都运行良好。该方法setProgressDrawable似乎使问题。
感谢您帮助我们。
私人无效updateProgressbar(查看视图,光标光标){
进度进度=(进度)视图
.findViewById(R.id.progressbarHorizontal);
progressBar.setProgressDrawable(view.getResources()。getDrawable(
R.drawable.greenprogress));
> progressBar.setProgress(1); 设置进度之前添加这种说法。
progressBar.setMax(cursor.getInt(cursor.getColumnIndex(numberpages)));
progressBar.setProgress(cursor.getInt(光标
.getColumnIndex(当前页)));
}
Using setProgressDrawable
for a ProgressBar
with custom colors does not work in a correct way for us. We use progressbars in the rows of a ListView
, but the progress is only displayed if there is more than one element in the list. In case of one element the progressbar is empty.
CursorAdapter.java:
public class CursorAdapter extends SimpleCursorAdapter {
public CursorAdapter(Context context, int layout, Cursor c, String[] from,
int[] to) {
super(context, layout, c, from, to);
}
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
updateProgressbar(view, cursor);
}
/**
* This method updates the progressbar using the "numberpages" and
* "currentpage" values.
*/
private void updateProgressbar(View view, Cursor cursor) {
ProgressBar progressBar = (ProgressBar) view
.findViewById(R.id.progressbarHorizontal);
progressBar.setProgressDrawable(view.getResources().getDrawable(
R.drawable.greenprogress));
progressBar.setMax(cursor.getInt(cursor.getColumnIndex("numberpages")));
progressBar.setProgress(cursor.getInt(cursor
.getColumnIndex("currentpage")));
}
}
/res/drawable/greenprogress.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="#33FF33"
android:endColor="#008000"
android:angle="270" />
</shape>
</clip>
</item>
</layer-list>
What's wrong with this code and why does it work only if there are more than one elements in the list? Without setting a custom ProgressBar style everything is running fine. The method setProgressDrawable seems to make problems.
Thank you for helping us.
private void updateProgressbar(View view, Cursor cursor) {
ProgressBar progressBar = (ProgressBar) view
.findViewById(R.id.progressbarHorizontal);
progressBar.setProgressDrawable(view.getResources().getDrawable(
R.drawable.greenprogress));
> progressBar.setProgress(1); "Add this statement before setting the progress.."
progressBar.setMax(cursor.getInt(cursor.getColumnIndex("numberpages")));
progressBar.setProgress(cursor.getInt(cursor
.getColumnIndex("currentpage")));
}
这篇关于问题使用ProgressBar.setProgressDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!