一手遮天 Android - view(自定义): 自定义圆形带进度提示的 loading 控件

项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

一手遮天 Android - view(自定义): 自定义圆形带进度提示的 loading 控件

示例如下:

/view/custom/MyLoadingDemo1.java

/**
 * 开发一个自定义圆形带进度提示的 loading 控件
 *
 * 参见 view/custom/MyLoading1.java
 */

package com.webabcd.androiddemo.view.custom;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.SystemClock;

import com.webabcd.androiddemo.R;

public class MyLoadingDemo1 extends AppCompatActivity {

    private MyLoading1 myLoading1;

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

        myLoading1 = findViewById(R.id.myLoading1);

        sample();
    }

    private void sample() {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                int progress = 0;
                while (true) {
                    // 更新当前进度值
                    myLoading1.setProgress(progress);
                    progress++;

                    if (progress > 100) {
                        break;
                    }

                    SystemClock.sleep(50);
                }
            }
        });
        thread.setName("thread_MyLoadingDemo1");
        thread.setDaemon(true);
        thread.start();
    }
}

/layout/activity_view_custom_myloadingdemo1.xml

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

    <com.webabcd.androiddemo.view.custom.MyLoading1
        android:id="@+id/myLoading1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

项目地址 https://github.com/webabcd/AndroidDemo
作者 webabcd

posted @ 2021-06-02 08:39  webabcd  阅读(195)  评论(0编辑  收藏  举报