2013-08-28 16 views
1

当我试图实现进度条时。我遇到了git hub应用程序 ,它实现了神话般的进度条微调器。我只是好奇他们是如何做到的。 他们如何在应用程序中调用微调器这样的方式活动UI加载的其他部分,但是 活动的一部分,即从服务器中一个可能提取的部分显示微调器。 由于Git hubis开源软件,我能够浏览代码。但是我不可能说得太多。Git Hub应用程序的进度条如何实现

GiHub App Source Code 任何知道他们如何实施进度条的人。

回答

1

它是一个定制样式的常规ProgressBar。例如。

https://github.com/github/android/blob/master/app/res/layout/progress_dialog.xml

<ProgressBar 
    android:id="@+id/pb_loading" 
    style="@style/Spinner" 
    android:layout_width="48dp" 
    android:layout_height="48dp" /> 

定义它应该使用其被定义为

https://github.com/github/android/blob/master/app/res/values/styles.xml

<style name="Spinner"> 
    <item name="android:indeterminate">true</item> 
    <item name="android:indeterminateDrawable">@drawable/spinner</item> 
    <item name="android:indeterminateDuration">2000</item> 
    <item name="android:indeterminateOnly">true</item> 
</style> 

即风格定义要使用一个自定义的可绘制的,其被定义为所述Spinner风格两部分LayerList

https://github.com/github/android/blob/master/app/res/drawable/spinner.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item android:drawable="@drawable/spinner_inner"/> 
    <item> 
     <rotate 
      android:fromDegrees="0" 
      android:interpolator="@android:anim/linear_interpolator" 
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:toDegrees="360" > 
      <bitmap 
       android:antialias="true" 
       android:filter="true" 
       android:src="@drawable/spinner_outer" /> 
     </rotate> 
    </item> 

</layer-list> 

inner image是猫标志,它被设置为旋转360°为虚线圆的outer images

+0

非常感谢zapl :)!我也找到了这个信息,以及他们如何在应用中调用微调器,这样活动用户界面加载的其他部分,但活动的一部分,即从服务器提取的一个概要显示微调器。 –

+0

我现在编辑了我的问题:) –