android进度条

简介: android进度条

为者败之,执者失之。——《道德经》

原生安卓实现的进度条

package com.example.uidemo.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import com.example.uidemo.R;
import java.math.BigDecimal;
import java.util.Locale;
public class ProgressBarActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
    private SeekBar seekBar;
    private ProgressBar progressBar1;
    private ProgressBar progressBar2;
    private TextView loadingText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar);
        seekBar=findViewById(R.id.seek_bar);
        progressBar1=findViewById(R.id.progress_bar1);
        progressBar2=findViewById(R.id.progress_bar2);
        loadingText=findViewById(R.id.loading_text);
        seekBar.setOnSeekBarChangeListener(this);
    }
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        String per=progress+"%";
        if(progress==seekBar.getMax()){
            loadingText.setText("加载完成");
            progressBar1.setVisibility(View.GONE);
        }else{
            loadingText.setText("正在加载中("+per+")");
            progressBar1.setVisibility(View.VISIBLE);
            progressBar2.setProgress(progress);
        }
    }
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
//        int progress = seekBar.getProgress();
//        System.out.println(progress);
//        progressBar2.setProgress(progress);
    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        progressBar2.setProgress(seekBar.getProgress());
    }
}


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
        tools:context=".activity.ProgressBarActivity"
        >
        <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                android:orientation="horizontal"
                android:gravity="center"
                >
                <ProgressBar
                        android:id="@+id/progress_bar1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />
                <TextView
                        android:id="@+id/loading_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="正在加载中(0%)"
                        android:textSize="20dp"
                        />
        </LinearLayout>
        <LinearLayout
                android:id="@+id/linearLayout2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintTop_toBottomOf="@id/linearLayout1"
                app:layout_constraintStart_toStartOf="parent"
                android:orientation="vertical"
                >
                <ProgressBar
                        android:id="@+id/progress_bar2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        style="?android:attr/progressBarStyleHorizontal"
                        android:progress="0"
                        android:max="100"
                        />
                <SeekBar
                        android:id="@+id/seek_bar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:max="100"
                        />
        </LinearLayout>
        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/linearLayout2"
                android:text="1.滑动下面的滑杆后,上面的进度条同步\n2.滑动到最大值后最上方ProgressBar改变(隐藏)"
                />
</androidx.constraintlayout.widget.ConstraintLayout>
相关文章
|
2月前
|
XML Java Android开发
Android实现自定义进度条(源码+解析)
Android实现自定义进度条(源码+解析)
68 1
|
11月前
|
Android开发 UED
Android 实现通知栏和进度条效果(适用于Android8.0以上)
Android 实现通知栏和进度条效果(适用于Android8.0以上)
122 0
|
28天前
|
Java API Android开发
19. 【Android教程】进度条 ProgressBar
19. 【Android教程】进度条 ProgressBar
21 4
|
2月前
|
XML API Android开发
Android 自定义View 之 圆环进度条
Android 自定义View 之 圆环进度条
|
2月前
|
XML Java Android开发
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
Android控件之基础控件——进度条类的view——TextView、Checkbox复选控件、RadioButton单选控件、ToggleButton开关、SeekBar拖动条、menu、弹窗
103 1
|
11月前
|
Android开发
Android 中ProgressDialog进度条对话框的使用(使用子线程模拟更新进度)
Android 中ProgressDialog进度条对话框的使用(使用子线程模拟更新进度)
127 0
|
2月前
|
XML API Android开发
Android 自定义View 之 饼状进度条
Android 自定义View 之 饼状进度条
|
2月前
|
Android开发 UED
[Android]ProgressBar进度条
[Android]ProgressBar进度条
45 0
|
2月前
|
XML Java Android开发
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
103 0
|
11月前
|
缓存 Java API
#7,Android开发 控件 ProgressBar 进度条
#7,Android开发 控件 ProgressBar 进度条