6

I have a very strange problem - I defined a custom progress drawable for a progress bar and

sometimes it shows and sometimes its not.

I tried cleaning my project, restarting eclipse and even restart the computer.

its still happens.

here is the progress drawable xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="5dp" />
    <gradient
        android:startColor="#6f7754"
        android:endColor="#858762"
        android:angle="90"/>
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <corners android:radius="5dp" />
        <gradient
                android:startColor="#ffba00"
                android:endColor="#af6c03"
                android:angle="90"/>
    </shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
    <shape 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">

        <corners
            android:radius="5dp" />
        <gradient
            android:startColor="#ffba00"
            android:endColor="#af6c03"
            android:angle="90" />
    </shape>
</clip>

and here's the xml where I use it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="2dp"
android:background="@drawable/quick_action_item_btn">

<ImageView
    android:id="@+id/icon" 
    android:layout_width="21dp" 
    android:layout_height="21dp"
    android:scaleType="centerInside"/>

<ProgressBar 
    android:id="@+id/progress"
    android:layout_width="20dp"
    android:layout_height="4dp"
    android:layout_marginTop="2dp"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:progressDrawable="@drawable/achievement_progress_bar"/>

</LinearLayout>
jzafrilla
  • 1,416
  • 3
  • 18
  • 41
piojo
  • 1,919
  • 4
  • 24
  • 40

3 Answers3

9

try with this

android:indeterminateDrawable="@drawable/yourXML"

it is working for me..

Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
  • add it in addition to android:progressDrawable="@drawable/achievement_progress_bar" ? or instead? – piojo Nov 12 '12 at 12:47
1

Its working fine for me. Just set your indeterminateDrawable to your custum xml file.It should be fine..

Abx
  • 2,852
  • 4
  • 30
  • 50
0

Perhaps this a similar problem to this one... SharedPreferences.onSharedPreferenceChangeListener not being called consistently

Is the custom xml defined as a variable of the activity? If not, perhaps it is being collected by the garbage collector. My suggestion is to make it a field variable of the class (the activity class).

Community
  • 1
  • 1
Mel
  • 6,214
  • 10
  • 54
  • 71