標籤:android progressbar
思路:想在ProgressBar上顯示百分比進度,百度、google搜尋一下,滿屏都是那個TextProgressBar,我沒引用那個,當時覺得應該可以更簡單的實現,於是直接就在UI上面嘗試,把ProgressBar放在RelativeLayout布局中,並在ProgressBar後面加個TextView,使這兩個控制項疊加就解決了,下面是xml,可以參考~
:
650) this.width=650;" title="QQ圖片20150316150605.png" alt="wKioL1UGghyRzq2zAABW3FfcjPA002.jpg" src="http://s3.51cto.com/wyfs02/M01/5B/52/wKioL1UGghyRzq2zAABW3FfcjPA002.jpg" />
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" style="?android:attr/progressBarStyleHorizontal" 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();//控制項疊加時,顯示在最上面,這句很重要
本文出自 “QYtag (Upspringing)” 部落格,請務必保留此出處http://qytag.blog.51cto.com/6125308/1621117
Android學習—超簡單實現帶進度ProgressBar捲軸