android开发笔记之materialish-progress

materialish-progress介绍

一个material 风格的滚动式进度条(progress wheel)
建议阅读一下参考资料的二篇文章,你就知道这个控件的使用了.

materialish-progress Demo

主是要实现当我们点击一个button时,在后台启动一个线程,从而实时的更新materialish-progress的进度条,进度条从0增加到100.

  1. 在build.gradle添加库的依赖
dependencies {
    implementation 'com.pnikosis:materialish-progress:1.7'
}

2.布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:material="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <com.pnikosis.materialishprogress.ProgressWheel
        android:id="@+id/progress_wheel"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_gravity="center"
        material:matProg_barColor="#EF5350"
        material:matProg_progressIndeterminate="true" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ProgressWhellDemo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/progress_wheel" />

</android.support.constraint.ConstraintLayout>

注意要加入:

xmlns:material="http://schemas.android.com/apk/res-auto"

或者会报错

3.逻辑实现:

import com.pnikosis.materialishprogress.ProgressWheel;

public class MainActivity extends AppCompatActivity {

    private final static String TAG = "ProgressWhellDemo";
    private ProgressWheel progress_wheel;
    private Button button;
    private int progress = 0;
    private static final int UPDATE_PROGRESS_WHELL = 0;


    private  Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case UPDATE_PROGRESS_WHELL:
                    Log.i(TAG,"handleMessage--progress:"+progress);
                    Log.i(TAG,"handleMessage--(float) (progress/100.0):"+(float) (progress/100.0));

                    progress_wheel.setProgress((float) (progress/100.0));
                    //progress_wheel.setInstantProgress((float) (progress/100.0));
                    break;
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        progress_wheel = (ProgressWheel)findViewById(R.id.progress_wheel);
        progress_wheel.setBarColor(Color.BLUE);
        progress_wheel.setVisibility(View.VISIBLE);

        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                updateProgress();
            }
        });
    }

    private void updateProgress() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (progress <= 99){
                    progress++;
                    Log.i(TAG,"sendEmptyMessageDelayed--"+progress);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    handler.sendEmptyMessage(UPDATE_PROGRESS_WHELL);
                }
            }
        }).start();
    }
}

参考资料

1.github materialish-progress
https://github.com/pnikosis/materialish-progress
2.materialish-progress
https://www.cnblogs.com/oshub/articles/4377497.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hfreeman2008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值