2016-11-19 116 views
1

我想要一個android中的靜態進度條。我將計算活動負載時的百分比,並在整個活動中顯示該百分比。靜態水平進度條android

目前我有: -

<ProgressBar 
style="?android:attr/progressBarStyleSmall" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/progressBar" 
android:layout_column="1" /> 

而且我在下面的方法設置進度條: -

ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar); 
progress.setProgress(term); 

它不顯示任何,只是加載圈繼續轉動。我只是想要顯示以下內容。它只是一個靜態值。

不,這不是因爲我不想增加百分比。我只想要一個靜態欄。

enter image description here

+0

默認情況下,進度條紡車,你需要的是風格=「@安卓風格/ Widget.ProgressBar.Horizo​​ntal」 –

+0

的可能的複製[如何顯示按百分比進度條狀態(HTTP:/ /stackoverflow.com/questions/9043683/how-to-show-progress-bar-status-by-percentage) – mallaudin

+0

沒有它不是重複的,因爲我不想增加百分比欄...它是一個靜態的。 – Anirban

回答

0

您可以用百分比的FrameLayout,並利用它們在TextView中設置進度值。

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ProgressBar 
     style="@android:style/Widget.ProgressBar.Horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:progress="50" 
     android:textAlignment="center" 
     android:id="@+id/progressBar" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="70 % complete" 
     android:textSize="20sp" 
     android:textColor="@android:color/white" 
     android:layout_gravity="center"/> 

</FrameLayout>