Android 梯形进度条、下载进度条;

Android 梯形进度条、下载进度条;_第1张图片

额,Gif有点卡;

梯形、矩形、圆角、背景色、前景色、进度条中的文字都可以改;




    
    
public class MainActivity extends AppCompatActivity {

    private ProgressButton pb1,pb2,pb3,pb4;
    private Button btn;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pb1 = findViewById(R.id.pb1);
        pb2 = findViewById(R.id.pb2);
        pb3 = findViewById(R.id.pb3);
        pb4 = findViewById(R.id.pb4);
        btn = findViewById(R.id.bt1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int num = (int) ((Math.random() * 9 + 1) * 8);
                pb1.setTrapezoidDiffer(num);
            }
        });
    }


    @Override
    protected void onResume() {
        super.onResume();
        simulateProgress();
    }

    private void simulateProgress() {
        ValueAnimator animator = ValueAnimator.ofInt(0, 100);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int progress = (int) animation.getAnimatedValue();
                pb2.setProgress(progress);
                pb3.setProgress(progress);
                pb4.setProgress(progress);
            }
        });
        animator.setRepeatCount(ValueAnimator.INFINITE);
        animator.setDuration(4000);
        animator.start();
    }
}

GitHub源码 : https://github.com/CuiChenbo/TrapezoidProgress

转载于:https://www.cnblogs.com/cuichen16/p/10785936.html

你可能感兴趣的:(Android 梯形进度条、下载进度条;)