circularprogressbar/smoothprogressbar开源视图使用学习

从光启
2023-12-01

github地址:https://github.com/castorflex/SmoothProgressBar

多彩圆形进度条和多彩水平进度条

colors.xml

定义变化的颜色内容,用gplus_colors来进行标示

<?xml version="1.0" encoding="utf-8"?>
<resources>

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

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

</resources>

activity_main.xml

start_btn-->进度条运行
end_btn-->进度条停止

android:indeterminate="true"-->默认为true,否则控件不显示

app:cpb_color="#FFee44"-->圆形进度条默认颜色
app:cpb_colors="@array/gplus_colors"-->定义圆形进度条的颜色数组
app:cpb_max_sweep_angle="300"-->最大弧度大小,不能超过360,不能小于0,否则报错
app:cpb_min_sweep_angle="10"-->最小弧度
 app:cpb_rotation_speed="1.0"-->转圈的速度,值越大,速度越快,值越小,越慢

app:cpb_sweep_speed="2.0"-->也是控制速度的,暂时未知
app:spb_colors="@array/gplus_colors"-->定义水平进度条颜色数组
 app:spb_mirror_mode="true"-->水平进度条由两侧向中心方向移动
app:spb_mirror_mode="false"-->水平进度条由左侧向右边移动
 app:spb_sections_count="4"-->线性进度条上显示4个色条
 app:spb_stroke_separator_length="4dp"->色块间隔
 app:spb_mirror_mode="true"-->true 两侧向中间靠拢,false 由左向右。
app:spb_stroke_width="4dp"-->色块上下厚度
app:spb_reversed="false"-->false 左向右,true 右向左。

  app:spb_progressiveStart_speed="5" -->色块移动开始速度

 app:spb_progressiveStop_speed="1"-->色块移动停止速度 

activty_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <Button
        android:id="@+id/start_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/end_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <fr.castorflex.android.circularprogressbar.CircularProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/circularProgressBar"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:indeterminate="true"
        app:cpb_color="#FFee44"
        app:cpb_colors="@array/gplus_colors"
        app:cpb_max_sweep_angle="300"
        app:cpb_min_sweep_angle="10"
        app:cpb_rotation_speed="1.0"
        app:cpb_stroke_width="4dp"
        app:cpb_sweep_speed="1.0" />

    <!-- app:spb_color="#FF0000" -->

    <fr.castorflex.android.smoothprogressbar.SmoothProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/smoothProgressBar"
        style="@style/SmoothProgressBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        app:spb_colors="@array/gplus_colors"
        app:spb_mirror_mode="true"
        app:spb_progressiveStart_activated="true"
        app:spb_progressiveStart_speed="1.5"
        app:spb_progressiveStop_speed="3.4"
        app:spb_reversed="false"
        app:spb_sections_count="4"
        app:spb_speed="2.0"
        app:spb_stroke_separator_length="4dp"
        app:spb_stroke_width="4dp" />

</LinearLayout>

MainActivity.java

package com.example.smoothprogressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import fr.castorflex.android.circularprogressbar.CircularProgressDrawable;

public class MainActivity extends Activity {
    private Button start_btn;
    private Button end_btn;
    //圆形进度条
    private fr.castorflex.android.circularprogressbar.CircularProgressBar circularProgressBar;
    //水平进度条
    private fr.castorflex.android.smoothprogressbar.SmoothProgressBar smoothProgressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        start_btn = (Button) findViewById(R.id.start_btn);
        end_btn = (Button) findViewById(R.id.end_btn);

        circularProgressBar = (fr.castorflex.android.circularprogressbar.CircularProgressBar) findViewById(R.id.circularProgressBar);
        smoothProgressBar = (fr.castorflex.android.smoothprogressbar.SmoothProgressBar) findViewById(R.id.smoothProgressBar);

        start_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                //圆形进度条转动
                CircularProgressDrawable drawable = (CircularProgressDrawable) circularProgressBar
                        .getIndeterminateDrawable();
                drawable.start();
                //水平进度条启动
                smoothProgressBar.progressiveStart();
            }
        });
        end_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                //圆形进度条停止转动
                CircularProgressDrawable drawable = (CircularProgressDrawable) circularProgressBar
                        .getIndeterminateDrawable();
                drawable.progressiveStop();
                //水平进度条停止启动
                smoothProgressBar.progressiveStop();

            }
        });
    }

}

我程序github地址:

 

转载于:https://www.cnblogs.com/androidsuperman/p/4326418.html

 类似资料: