Friday, December 28, 2018

ProgressBar not shown due to animation disabled on phone | Android Programming


I noticed the ProgressBar used in my app suddenly stopped working.

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:progressDrawable="@drawable/circular_progress_bar"/>



res/drawable/circular_progress_bar.xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="90"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="360">

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="7.0">

        <gradient
            android:centerColor="#2277DD"
            android:endColor="#2277DD"
            android:startColor="#2277DD"
            android:angle="0"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

I played with the code for an hour or so but cannot find out why. It turned out the reason is that I had turned off animation on my phone. To turn it back on, go to Settings/Developer options, find all the "animation scale" options and set the scales to a value other than "Animation off". Restart the app on the phone and the ProgressBar will come back.

No comments:

 
Get This <