歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> ProgressWheel:Android開源圓環進度條

ProgressWheel:Android開源圓環進度條

日期:2017/3/1 9:36:19   编辑:Linux編程

這是一個自定義Android組件,用於代替標准進度條組件。實現各種進度條樣式,包括圓環,掃描等。

XML:

在你的attr.xml(res/value)中加入以下

<declare-styleable name="ProgressWheel">
<attr name="text"format="string"/>
<attr name="textColor"format="color"/>
<attr name="textSize"format="dimension"/>
<attr name="barColor"format="color"/>
<attr name="rimColor"format="color"/>
<attr name="rimWidth"format="dimension"/>
<attr name="spinSpeed"format="integer"/>
<attr name="circleColor"format="color"/>
<attr name="radius"format="dimension"/>
<attr name="barWidth"format="dimension"/>
<attr name="barLength"format="dimension"/>
<attr name="delayMillis"format="dimension"/>
<attr name="contourColor"format="color"/>
<attr name="contourSize"format="float"/>
</declare-styleable>

在你的root view 中加入

xmlns:ProgressWheel="http://schemas.android.com/apk/res/com.visualdenim.schooltraq"

在你的xml合適的地方加入 組件

<com.todddavies.components.progressbar.ProgressWheel
android:id="@+id/pw_spinner"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
ProgressWheel:text="Authenticating..."
ProgressWheel:textColor="#222"
ProgressWheel:textSize="14sp"
ProgressWheel:rimColor="#330097D6"
ProgressWheel:barLength="60dp"
ProgressWheel:barColor="#0097D6"
ProgressWheel:barWidth="5dp"
ProgressWheel:rimWidth="2dp"/>

你需要從layout中獲得進度條,或者初始化

ProgressWheel pw = newProgressWheel(myContext, myAttributes);
ProgressWheel pw = (ProgressWheel) findViewById(R.id.pw_spinner);

使用.spin() 開始進度條滾動, .stopSpinning 停止進度條滾動

增加進度有點棘手, 你可以調用.incrementProgress(), 但是這樣就超過了360度, 因為一個圓有360度, 你超過360度就會自動重置, 一個百分百自動分配。

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved