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>

хочу такой индикатор выполнения

0
0
284
1

Ответы 1

Не уверен, почему ваш собственный не работает, но этот работает с вашим activity.java, поэтому ваш XML определенно является проблемой. Вот индикатор выполнения, который действительно работает. Если вы хотите добавить процент, я предлагаю взглянуть здесь: https://github.com/ylyc/circular_progress_bar.

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout 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"
    tools:context = ".MainActivity">

    <ProgressBar android:indeterminate = "true"
        android:useLevel = "true"
        android:layout_centerInParent = "true"
        android:indeterminateDrawable = "@drawable/circular"
        android:layout_width = "wrap_content" android:layout_height = "wrap_content"
        android:id = "@+id/progressBar1"></ProgressBar>

</RelativeLayout>

Привет, @Kamarudeen Ayankunbi, как я могу добавить библиотеку, которую вы упомянули в моем проекте Android. Пожалуйста, уточните ???

FIRE 07.07.2018 15:06

Попробуйте это: stackoverflow.com/questions/32600325/…

Kamarudeen Ayankunbi 07.07.2018 17:55

Другие вопросы по теме