android - 在 ProgressBar 中显示数字

标签 android progress-bar progressdialog

我有一个进度条。 它工作正常,但我需要显示最大值和当前值。 他们不在那里。

我需要更改为 ProgressDialog 吗?

澄清:

我正在显示一个 ProgressBar。 条形图完美显示,但我希望数字也显示出来。 因此,例如,如果最大值为 1000,当前点为 300,那么我希望 1000 出现在条形的末端,而 300 出现在条形上或下方的某个位置。

我正在使用此类作为列表适配器来填充 ListView。 显示的行取决于“奖励”数组中的数据类型。 在执行 ProgressBar 时,它没有显示数字。

代码:

private class AwardsAdapter extends ArrayAdapter <AwardItem>{


    private ArrayList<AwardItem> awards = new ArrayList<AwardItem>();

    public AwardsAdapter(Context context, int textViewResourceId, ArrayList<AwardItem> awards) {
        super(context, textViewResourceId,awards);
        this.awards = awards;
        // TODO Auto-generated constructor stub
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)AwardsActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.awards_row, parent, false);
        }
        AwardItem award = awards.get(position);
        ProgressBar pb = (ProgressBar) v.findViewById(R.id.pgbAwardProgress);

        if(award.award_type == PROGRESSIVE) {
            pb.setVisibility(View.VISIBLE);
            pb.setMax(award.requirement);
            pb.setProgress(award.current_amount);
            pb.setIndeterminate(false);

        } else {
            pb.setVisibility(View.GONE);
        }
        ((TextView) v.findViewById(R.id.tvwShortMessage)).
                      setText(MessageBuilder.buildMessage(AwardsActivity.this, award.award_text, 
                              Integer.valueOf(award.requirement).toString()));

        return v;
    }

}

布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="fill_parent"
 android:layout_height="wrap_content">
<TextView android:id="@+id/tvwShortMessage"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvwLongMessage"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tvwShortMessage"/>
<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"    
android:layout_marginBottom="15dp" 
android:layout_below="@id/tvwLongMessage">
<ProgressBar
android:id="@+id/pgbAwardProgress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"    
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginRight="5dp" 
android:layout_marginTop="5dp" 
android:layout_marginBottom="15dp" 
android:layout_alignParentTop="true"/>
</LinearLayout>
</RelativeLayout>

这是最终屏幕。 它是迄今为止一系列任务及其进度的列表。 每条“线”都是一个单独的进度条。

enter image description here

最佳答案

新的 NumberProgressBar 库:

Number progress bar

看看这个很棒的图书馆 NumberProgressBar在 Github 中有更多颜色样式。

enter image description here

致谢:代马家先生,

据他说NumberProgressBar是酒吧, slim 又性感(每个男人都想要!)。

关于android - 在 ProgressBar 中显示数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8080329/

相关文章:

java - Android:函数在 Thread 中不起作用,但在其他情况下起作用(尝试添加 ProgressDialog)

android - EOFException Volley 错误

java - 如何在某个变量值变化时触发onPerformSync

java - 后台服务在 onCreate() 和 onResume() 中随机停止在 android 中工作

jquery - 导航进度条

javascript - XMLHttpRequest.upload 进度事件仅适用于 IE

java - AsyncTask 中的 ProgressDialog 关闭不起作用

使用 Picasso 应用转换时,某些用户的 Android 应用程序崩溃

android - 以编程方式更改进度条的颜色

java - 所有 Activity 的进度对话框样式相同