android– 在ProgressBar中显示数字

android– 在ProgressBar中显示数字,第1张

概述我有一个ProgressBar.它工作正常,但我需要显示最大值和当前值.他们不在那里.我需要更改为ProgressDialog吗?澄清:我正在展示ProgressBar.酒吧出现完美,但我希望数字也出现.因此,例如,最大值为1000,当前点为300,然后我想要1000出现,栏的结尾和300出现在栏上或其下方.我使用此类作

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

我需要更改为ProgressDialog吗?

澄清:

我正在展示Progressbar.
酒吧出现完美,但我希望数字也出现.
因此,例如,最大值为1000,当前点为300,然后我想要1000出现,栏的结尾和300出现在栏上或其下方.

我使用此类作为List Adapter来填充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"><ProgressbarandroID:ID="@+ID/pgbAwardProgress"androID:layout_wIDth="fill_parent"androID:layout_height="wrap_content"    androID:layout_marginRight="5dp" androID:layout_margintop="5dp" androID:layout_marginBottom="15dp" androID:layout_alignParenttop="true"/></linearLayout></relativeLayout>

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

解决方法:

为什么不手动添加文本,这似乎是一个非常简单的方法,我把它放在我想要的地方,但你可以根据需要改变布局.

对不起,如果代码中有任何错误,我没有运行它.

XML:

<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"><ProgressbarandroID:ID="@+ID/pgbAwardProgress"androID:layout_wIDth="fill_parent"androID:layout_height="wrap_content"    androID:layout_marginRight="5dp" androID:layout_margintop="5dp" androID:layout_marginBottom="15dp" androID:layout_alignParenttop="true"/></linearLayout><TextVIEw androID:ID="@+ID/pgbAwardProgresstext"androID:typeface="sans"androID:textSize="14sp"androID:textStyle="italic"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:layout_below="@+ID/pgbAwardProgress"androID:layout_alignParentRight="true"androID:visibility="gone"/></relativeLayout>

类:

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);            TextVIEw progresstext = ((TextVIEw) v.findVIEwByID(R.ID.pgbAwardProgresstext));            progresstext.setVisibility(VIEw.VISIBLE);            progresstext.setText(award.current_amount+"/"+award.requirement);        } 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;    }}
总结

以上是内存溢出为你收集整理的android – 在ProgressBar中显示数字全部内容,希望文章能够帮你解决android – 在ProgressBar中显示数字所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099568.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存