最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android實(shí)現(xiàn)動(dòng)態(tài)顯隱進(jìn)度條

 更新時(shí)間:2021年07月29日 11:52:32   作者:藍(lán)之靜云  
這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)動(dòng)態(tài)顯隱進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android實(shí)現(xiàn)動(dòng)態(tài)顯隱進(jìn)度條的具體代碼,供大家參考,具體內(nèi)容如下

調(diào)用

ProgressUtil.startProgress(this, new ProgressUtil.ICallback() {
                @Override
                public void progress(int count) {
                    LogUtil.d(count + "%");
                }
            }); 

ProgressUtil

package com.coral3.common_module.utils;

import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.coral3.common_module.R;
import java.sql.Time;
import java.util.Timer;
import java.util.TimerTask;

public class ProgressUtil {

    private static View progressContainer;
    private static TextView tvView;
    private static ProgressBar progressView;
    private static ViewGroup contentView;
    private static Timer timer = new Timer();
    private static TimerTask task;
    private static int count = 0;
    private static ICallback myICallback;
    private static Handler handler = new Handler(new Handler.Callback(){

        @Override
        public boolean handleMessage(Message msg) {
            if(msg.what == 0x1){
                count++;
                progressView.setProgress(count);
                tvView.setText(count + "%");
                myICallback.progress(count);
            }
            return false;
        }
    });

    public static void startProgress(Context context, ICallback iCallback){
        if(null == contentView) contentView = ((Activity)context).findViewById(android.R.id.content);
        if (progressContainer == null) {
            progressContainer = LayoutInflater.from(context).inflate(R.layout.view_progress, null, false);
            progressView = progressContainer.findViewById(R.id.pb_common);
            tvView = progressContainer.findViewById(R.id.tv_progress);
            contentView.addView(progressContainer);
        } else {
            progressContainer.setVisibility(View.VISIBLE);
        }
        myICallback = iCallback;
        task = new TimerTask() {
            @Override
            public void run() {

                if(count > 99){
                    hideProgressInUiThread((Activity) context);
                }else{
                    handler.sendEmptyMessage(0x1);
                }
            }
        };
        if(timer == null) timer = new Timer();
        timer.schedule(task, 10, 1000/60);
    }

    public static void endTimer(){
        timer.cancel();
        task.cancel();
        task = null;
        timer = null;
        count = 0;
    }

    public static void hideProgress(){
        if (progressContainer != null) {
            endTimer();
            progressContainer.setVisibility(View.GONE);
        }
    }

    public static void startProgressInUiThread(Context context, ICallback iCallback){
        ((Activity)context).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                startProgress(context, iCallback);
            }
        });
    }

    public static void hideProgressInUiThread(Activity activity){
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                hideProgress();
            }
        });
    }

    public interface ICallback{
        void progress(int count);
    }
}

view_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="8dp"
            android:layout_height="match_parent">
            <ProgressBar android:id="@+id/pb_common"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:progress="10"
                style="@style/Widget.AppCompat.ProgressBar.Horizontal"></ProgressBar>
            <TextView
                android:id="@+id/tv_progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0%"/>
        </LinearLayout>

</RelativeLayout>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

德惠市| 攀枝花市| 钟祥市| 宜都市| 兰州市| 天镇县| 朝阳市| 鄂州市| 万州区| 大兴区| 东阳市| 普兰店市| 花莲市| 浪卡子县| 客服| 高雄县| 大埔区| 揭西县| 罗城| 洛宁县| 奈曼旗| 浦江县| 繁昌县| 宽甸| 利川市| 长宁区| 离岛区| 沙雅县| 芷江| 神农架林区| 香港 | 合山市| 华安县| 马尔康县| 罗甸县| 台东县| 克什克腾旗| 通道| 安龙县| 保亭| 宜宾县|