android 梯形按钮_Android 梯形进度条、下载进度条;

本文展示了如何在Android应用中创建自定义的梯形进度条和按钮,包括改变形状、颜色、尺寸和文字大小。通过XML布局和Java代码实现动态效果,如随机梯形宽度变化和无限循环的进度更新。
摘要由CSDN通过智能技术生成

额,Gif有点卡;

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

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">

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

android:id="@+id/bt1"

android:text="梯形变化"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

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

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

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

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();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值