1

当我试图实现进度条时。我遇到了 git hub 应用程序,它实现了很棒的进度条微调器。我只是好奇他们是怎么做到的。他们如何在应用程序中调用微调器,以便加载活动 UI 的其他部分,但活动的一部分,即从服务器可能获取的一个显示微调器。由于 Git hub 是开源软件,我能够浏览代码。但我无法理解太多。

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

4

1 回答 1

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" />

定义它应该使用Spinner定义为的样式

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>

该样式定义了要使用的自定义可绘制对象,该可绘制对象定义为两部分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>

内部图像是猫标志,设置为 360° 旋转的外部图像是虚线圆圈。

于 2013-08-28T10:37:54.820 回答