さまよえる、Android

Androidのプログラミングで便利なことや残しておきたいことを残しておく。もしオススメのライブラリがあったら教えてくださいね。

AndroidのUIライブラリ、SmoothProgressBarを使ってみた。

github.com

https://github.com/castorflex/SmoothProgressBar/raw/master/screenshots/SPB_sample.gif

いつもの

    compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <fr.castorflex.android.smoothprogressbar.SmoothProgressBar
        android:id="@+id/google_now"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/GNowProgressBar"
        android:indeterminate="true"/>

</RelativeLayout>

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="GNowProgressBar" parent="SmoothProgressBar">
        <item name="spb_stroke_separator_length">8dp</item>
        <item name="spb_sections_count">2</item>
        <item name="spb_speed">1.7</item>
        <item name="spb_progressiveStart_speed">2</item>
        <item name="spb_progressiveStop_speed">3.4</item>
        <item name="spb_interpolator">spb_interpolator_acceleratedecelerate</item>
        <item name="spb_mirror_mode">false</item>
        <item name="spb_reversed">false</item>
        <item name="spb_gradients">true</item>
        <item name="spb_colors">@array/gplus_colors</item>
        <item name="spb_progressiveStart_activated">true</item>
        <item name="spb_generate_background_with_colors">false</item>
    </style>


</resources>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer-array name="gplus_colors">
        <item>@color/gplus_color_1</item>
        <item>@color/gplus_color_2</item>
        <item>@color/gplus_color_3</item>
        <item>@color/gplus_color_4</item>
    </integer-array>

    <color name="gplus_color_1">#3e802f</color>
    <color name="gplus_color_2">#f4b400</color>
    <color name="gplus_color_3">#427fed</color>
    <color name="gplus_color_4">#b23424</color>

</resources>

流れを逆にしたい場合は、trueにする。

<item name="spb_reversed">false</item>

グラーデーションの切り替えは、falseにする。

<item name="spb_gradients">true</item>


停止したい時は、

SmoothProgressBar mProgressBar1 = (SmoothProgressBar) findViewById(R.id.google_now);
mProgressBar1.progressiveStop();

開始したい時は、

SmoothProgressBar mProgressBar1 = (SmoothProgressBar) findViewById(R.id.google_now);
mProgressBar1.progressiveStart();