思路:想在ProgressBar上显示百分比进度,百度、google搜索一下,满屏都是那个TextProgressBar,我没引用那个,当时觉得应该可以更简单的实现,于是直接就在UI上面尝试,把ProgressBar放在RelativeLayout布局中,并在ProgressBar后面加个TextView,使这两个控件叠加就解决了,下面是xml,可以参考~
效果图:

XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:background="#FFFFFF">
<TextView
android:id="@+id/tvGraphType"
android:layout_width="84dp"
android:layout_height="wrap_content"
android:padding="2sp"
android:gravity="right"
android:maxLength="6"
android:textColor="#666666"
android:text="type"
android:textSize="13sp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ProgressBar
android:id="@+id/pbGraph"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="2sp"
android:progressDrawable="@drawable/pbarcolor_out"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"/>
<TextView
android:id="@+id/tvGraphPercent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#666666"
android:text="%"
android:textSize="13sp"/>
</RelativeLayout>
</LinearLayout>
进度条上百分比进度的计算也贴一下吧:
//pbOuts 是ProgressBar,outPercent 是用于显示百分比的TextView
holder.pbOuts.setMax(Graph.getRound(Maxout));
holder.pbOuts.setProgress(Graph.getRound(Outcomes));
if (Maxout>0) {
holder.outPercent.setText(String.valueOf(Graph.getRound((Outcomes*100/Maxout)))+"%");
}else {
holder.outPercent.setText("0%");
}
holder.outPercent.bringToFront();//控件叠加时,显示在最上面,这句很重要