额,Gif有点卡;

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <choi.ccb.com.trapezoidprogress.progressbar.ProgressButton
        android:id="@+id/pb1"
        android:layout_width="match_parent"
        android:layout_height="28dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="15dp"
        app:progressbtn_radius="1"
        app:progressbtn_trapezoid_differ="15dp"
        app:progressbtn_enable_trapezoid="true"
        app:progressbtn_text_size="14dp"
        app:progressbtn_background_color="#43B2BF"
        app:progressbtn_background_second_color="#8D99AF" />
    <Button
        android:id="@+id/bt1"
        android:text="梯形变化"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <choi.ccb.com.trapezoidprogress.progressbar.ProgressButton
        android:id="@+id/pb2"
        android:layout_width="match_parent"
        android:layout_height="28dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="15dp"
        app:progressbtn_radius="1"
        app:progressbtn_trapezoid_differ="15dp"
        app:progressbtn_enable_trapezoid="false"
        app:progressbtn_text_size="14dp"
        app:progressbtn_background_color="@color/colorAccent"
        app:progressbtn_background_second_color="#ccc" />
    <choi.ccb.com.trapezoidprogress.progressbar.ProgressButton
        android:id="@+id/pb3"
        android:layout_width="match_parent"
        android:layout_height="28dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="15dp"
        app:progressbtn_radius="0"
        app:progressbtn_trapezoid_differ="15dp"
        app:progressbtn_enable_trapezoid="false"
        app:progressbtn_text_size="14dp"
        app:progressbtn_background_color="#43B2BF"
        app:progressbtn_background_second_color="#8D99AF" />
    <choi.ccb.com.trapezoidprogress.progressbar.ProgressButton
        android:id="@+id/pb4"
        android:layout_width="match_parent"
        android:layout_height="28dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="15dp"
        app:progressbtn_radius="1"
        app:progressbtn_trapezoid_differ="15dp"
        app:progressbtn_enable_trapezoid="true"
        app:progressbtn_text_size="14dp"
        app:progressbtn_background_color="#fb2"
        app:progressbtn_background_second_color="#999" />

</LinearLayout>
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

posted on 2019-01-23 16:19  香蕉你个博纳纳  阅读(1583)  评论(0编辑  收藏  举报