Android Progressbar圆形进度条顺时针旋转

原文链接:https://blog.csdn.net/zhaozhiwen6140/article/details/51849835

在网络请求拿取数据的过程中,如果出现网速太慢以及数据量太大的情况,一般加入一个要求用户先进行等待的界面,等到数据全部拿到再进行展示效果会好一些,展示如下。


1.首先在drawable文件夹下新建一个animated-rotate标签的xml文件,如下:

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_custom_loading"
    android:pivotX="50%"
    android:pivotY="50%"
    android:fromDegrees="0"
    android:toDegrees="360"/>
ic_custom_loading是要展示的图片
2.在main.xml文件中实现对Progressbar的布局,如下:

 
<LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/progressbar"
android:layout_width="28dp"
android:layout_height="28dp"
android:indeterminateDrawable="@drawable/load_animate" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/string_loadings"
android:textSize="18sp"/>
</LinearLayout>
运行,出现图片中的效果,图片会一直旋转,完成。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Winform中的ProgressBar默认是直线形式的进度条,如果想要使用圆形进度条,可以通过自定义控件来实现。具体步骤如下: 1. 创建一个新的Winform项目,在窗体中拖入一个PictureBox控件和一个Timer控件。 2. 在PictureBox的Paint事件中编写绘制圆形进度条的代码。可以使用Graphics对象的DrawArc方法来绘制圆弧,通过计算百分比来确定圆弧的长度。 3. 在Timer的Tick事件中更新进度条的值,并调用PictureBox的Invalidate方法来重新绘制。 以下是一个简单的示例代码: ```c# public partial class Form1 : Form { private int progressValue = 0; // 进度条的值 private Timer timer; // 定时器控件 public Form1() { InitializeComponent(); timer = new Timer(); timer.Tick += Timer_Tick; timer.Start(); } private void Timer_Tick(object sender, EventArgs e) { if (progressValue < 100) { progressValue++; } else { timer.Stop(); } pictureBox1.Invalidate(); // 重绘进度条 } private void pictureBox1_Paint(object sender, PaintEventArgs e) { // 计算圆弧的角度和长度 float angle = progressValue / 100f * 360f; float length = angle / 360f * pictureBox1.Width; // 绘制圆弧 e.Graphics.DrawArc(Pens.Blue, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height), -90, angle); } } ``` 通过以上的代码,就可以实现一个简单的Winform圆形进度条。记得在窗体上加入一个PictureBox控件,并将其Paint事件和Timer的Tick事件与相应的方法关联起来。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值