Android progressBar不显示或不可见

时间:2018-07-05 16:50:18

标签: android progress-bar android-progressbar

我的自定义进度栏不显示。我在我的活动中为其设置动画,并为其使用可绘制资源文件。这是我的代码。

Activity.java

  ProgressBar progressBar;

   @Override
   protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
      progressBar =  findViewById(R.id.progressBar);
    ObjectAnimator animation = ObjectAnimator.ofInt(progressBar, "progress", 
   0, 500); 
    animation.setDuration(5000); // in milliseconds
    animation.setInterpolator(new DecelerateInterpolator());
    animation.start();

activity.xml

      <ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleHorizontal"

    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:max="500"
    android:progress="0"
    android:progressDrawable="@drawable/circular"
    app:layout_constraintBottom_toBottomOf="@+id/relativeLayout"
    app:layout_constraintEnd_toEndOf="@+id/relativeLayout"
    app:layout_constraintHorizontal_bias="0.475"
    app:layout_constraintStart_toStartOf="@+id/relativeLayout"
    app:layout_constraintTop_toTopOf="@+id/relativeLayout"
    app:layout_constraintVertical_bias="0.153" />

drawableResource.xml

     <?xml version="1.0" encoding="utf-8"?>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:useLevel="true"
        android:indeterminate="true"
        android:innerRadiusRatio="2.3"
        android:shape="ring"
        android:thickness="3.8sp" >
        <solid android:color="@color/colorPrimary" />
     </shape>

want this kind of progress bar

1 个答案:

答案 0 :(得分:0)

Here 正是您想要的。

将此依赖项添加到gradle中。

dependencies {
    implementation 'com.github.lzyzsd:circleprogress:1.2.1' // or compile for old versions gradle
}

在您的项目级别build.gradle

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

在您的布局中添加它。

<com.github.lzyzsd.circleprogress.DonutProgress
    android:layout_marginLeft="50dp"
    android:id="@+id/donut_progress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    custom:donut_progress="30"/>

有关更多自定义的信息,请参见library link

enter image description here