【问题标题】:How to make dynamic ring progress bar in android?如何在android中制作动态环形进度条?
【发布时间】:2017-08-03 04:47:59
【问题描述】:

我想创建一个圆形进度条,显示文件上传和下载的进度,就像什么应用程序显示的那样。我在 github 上看到了可用的数字或库。我确实知道有人问过这个问题,并且我已经完成了这些问题以及下面链接中提到的问题。

https://github.com/lzyzsd/CircleProgress
https://stackoverflow.com/questions/37238185/how-to-create-a-circularprogressbar-like-whatsapp-during-image-uploading

但上面的链接是指图书馆。有什么方法可以在不使用任何库的情况下创建圆形进度条?

在 stackoverflow 的一个链接中,我在下面的代码中找到了

    ObjectAnimator animation = ObjectAnimator.ofInt (progressBar, "progress", 0, 500); 
    animation.setDuration (5000); 
    animation.setInterpolator (new DecelerateInterpolator());

但上面的代码并没有动态设置进度。表示进度条工作 5 秒。进度条不必须始终运行 5 秒。文件大小可能会有所不同,进度条也会有所不同。我的问题是如何在不使用库的情况下动态制作循环进度条?

【问题讨论】:

    标签: android android-progressbar


    【解决方案1】:
    【解决方案2】:

    您可以通过以下方式做到这一点,当图像视图从服务器保持时,它会隐藏进度条,直到从服务器加载文件,进度条旋转。

               <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    
                    <ProgressBar
                        android:id="@+id/progress"
                        android:visibility="visible"
                        style="?android:attr/progressBarStyleLarge"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:maxHeight="55dip"
                        android:minHeight="35dip"
                        android:minWidth="55dip"
                        android:maxWidth="10dip"
                        android:layout_centerVertical="true"
                        android:layout_centerHorizontal="true" />
    
                     <ImageView
                        android:id="@+id/image"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:visibility="visible"/>
                </RelativeLayout>
    

    【讨论】:

      【解决方案3】:

      希望对你有帮助

      布局 Xml

      <ProgressBar
         android:id="@+id/progressBar"
         style="?android:attr/progressBarStyleHorizontal"
         android:layout_width="150dp"
         android:layout_height="150dp"
         android:layout_alignParentBottom="true"
         android:layout_centerHorizontal="true"
         android:max="500"
         android:progress="0"
         android:progressDrawable="@drawable/circular" />
      

      现在使用以下形状在您的资源中创建可绘制对象。使用半径(您可以使用innerRadius 而不是innerRadiusRatio)和厚度值。

      <shape
          android:innerRadiusRatio="2.3"
          android:shape="ring"
          android:thickness="3.8sp" >
          <solid android:color="@color/yourColor" />
      

      【讨论】:

        【解决方案4】:

        1.使用这个库可能对你有帮助:

        https://github.com/CardinalNow/Android-CircleProgressIndicator

        1. 你也可以试试这个:

        Show Progress bar while downloading

        【讨论】:

        • 这就是为什么我给你两个选项 1. 有库和 2. 没有库
        猜你喜欢
        • 1970-01-01
        • 2013-01-19
        • 1970-01-01
        • 1970-01-01
        • 2018-11-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多