欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android實現(xiàn)動態(tài)顯示隱藏進度條

 更新時間:2021年08月19日 16:10:19   作者:藍之靜云  
這篇文章主要為大家詳細介紹了android實現(xiàn)動態(tài)顯示隱藏進度條,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了android實現(xiàn)動態(tài)顯示隱藏進度條的具體代碼,供大家參考,具體內(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>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 利用Android中的TextView實現(xiàn)逐字顯示動畫

    利用Android中的TextView實現(xiàn)逐字顯示動畫

    在安卓程序啟動的時候,想逐字顯示一段話,每個字都有一個從透明到不透明的漸變動畫。那如何顯示這個效果,下面一起來看看。
    2016-08-08
  • Android中TextView實現(xiàn)部分文字可點擊跳轉

    Android中TextView實現(xiàn)部分文字可點擊跳轉

    這篇文章主要為大家詳細介紹了Android中TextView實現(xiàn)部分文字可點擊跳轉的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Jetpack Compose布局的使用詳細介紹

    Jetpack Compose布局的使用詳細介紹

    Jetpack Compose是用于構建原生Android界面的新工具包。它可簡化并加快Android上的界面開發(fā),使用更少的代碼、強大的工具和直觀的 Kotlin API,快速讓應用生動而精彩
    2022-09-09
  • android studio 3.6 中配置svn的教程

    android studio 3.6 中配置svn的教程

    這篇文章主要介紹了android studio 3.6 配置svn的教程,本文所用的as版本是3.6.1,通過圖文實例相結合給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • Android 3D旋轉動畫效果實現(xiàn)分解

    Android 3D旋轉動畫效果實現(xiàn)分解

    如何實現(xiàn)View的3D旋轉效果,實現(xiàn)的主要原理就是圍繞Y軸旋轉,同時在Z軸方面上有一個深入的縮放,具體實現(xiàn)代碼如下,感興趣的朋友可以參考下哈
    2013-06-06
  • Android Bitmap壓縮方式分析

    Android Bitmap壓縮方式分析

    這篇文章主要介紹了Android Bitmap壓縮方式分析的相關資料,需要的朋友可以參考下
    2017-07-07
  • Android應用中實現(xiàn)跳轉外部瀏覽器打開鏈接功能

    Android應用中實現(xiàn)跳轉外部瀏覽器打開鏈接功能

    在開發(fā)Android應用程序時,有時候我們需要讓用戶跳轉到外部瀏覽器打開特定的鏈接,例如打開一個網(wǎng)頁、下載文件等,本文將介紹如何在Android應用中實現(xiàn)跳轉外部瀏覽器打開鏈接的功能,感興趣的朋友一起看看吧
    2024-06-06
  • 詳解Android中使用Notification實現(xiàn)進度通知欄(示例三)

    詳解Android中使用Notification實現(xiàn)進度通知欄(示例三)

    這篇文章主要介紹了詳解Android中使用Notification實現(xiàn)進度通知欄(示例三),具有一定的參考價值,有興趣的可以了解一下。
    2016-12-12
  • 總是聽到有人說AndroidX,到底什么是AndroidX

    總是聽到有人說AndroidX,到底什么是AndroidX

    這篇文章主要介紹了總是聽到有人說AndroidX,到底什么是AndroidX,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-05-05
  • Android RecyclerView網(wǎng)格布局(支持多種分割線)詳解(2)

    Android RecyclerView網(wǎng)格布局(支持多種分割線)詳解(2)

    這篇文章主要為大家詳細介紹了Android RecyclerView網(wǎng)格布局,支持多種分割線,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02

最新評論