1

I am working with custom progress bar using indeterminateDrawable property, code is below, when I removed indeterminateDrawable property then it shown in center but not shown center with this property. please help me.

<LinearLayout
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center" >

    <ProgressBar
        android:id="@+id/workingProgressBar"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:indeterminateDrawable="@drawable/startup_anim"
        android:indeterminateOnly="true" />
</LinearLayout>

drawable/startup_anim.xml

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:drawable="@drawable/animation4"
    android:duration="100"/>
<item
    android:drawable="@drawable/animation3"
    android:duration="100"/>
<item
    android:drawable="@drawable/animation2"
    android:duration="100"/>
<item
    android:drawable="@drawable/animation1"
    android:duration="100"/>
<item
    android:drawable="@drawable/animation0"
    android:duration="100"/>

</animation-list>
OcuS
  • 5,320
  • 3
  • 36
  • 45
Jignesh Ansodariya
  • 12,583
  • 24
  • 81
  • 113

2 Answers2

2

The answer here solves such issues by using a <scale> inside each <item> of an <animation-list> like this:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:duration="100">
        <scale
            android:drawable="@drawable/img_1"
            android:scaleGravity="center"/>
    </item>
    <item android:duration="100">
        <scale
            android:drawable="@drawable/img_2"
            android:scaleGravity="center"/>
    </item>
</animation-list>
Community
  • 1
  • 1
SteelBytes
  • 6,905
  • 1
  • 26
  • 28
-1

Never use android:layout_width="match_parent" or android:layout_width="fill_parent" while creating ProgressBar, it will stretch it and the result won't be as you expect. And if you want to center your ProgressBar in your Activity or Fragment just use this layout :

    <RelativeLayout
    android:id="@id/android:empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ProgressBar
        android:id="@+id/workingProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:indeterminateDrawable="@drawable/startup_anim"
        android:indeterminateOnly="true" />

   </RelativeLayout>
hardartcore
  • 16,886
  • 12
  • 75
  • 101