ProgressBar not an instance of LayerDrawable

494 views Asked by At

I am trying to implement my own custom progressbar using 9 patch images. I am looking at the Sound ProgressBar example. http://www.jagsaund.com/blog/2011/11/6/customizing-your-progress-bar-part-one.html

I have two problems that I have been unable to figure out why its happening:

  1. No matter what I do my progressbar is not an instance of layerdrawable, I am not sure why this is happening so I am unable to get reference to the layer I want and change it grammatically.

  2. The 9 patch image starts off stretched to the entire width of the container (relativelayout) not sure how to tell it to not automatically scale so I can control its width grammatically.

Here are the following code snipets:

Drawable progressbar.xml

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@android:id/background"
        android:drawable="@drawable/progressbar_bg" >
  </item>
  <item android:id="@+id/progress">
    <bitmap
      android:src="@drawable/progressbar"
      android:tileMode="repeat" />
  </item>
</layer-list>

Style.xml

<style name="Widget">
</style>

<style name="Widget.ProgressBar">
    <item name="android:indeterminateOnly">true</item>
    <item name="android:indeterminateBehavior">repeat</item>
    <item name="android:indeterminateDuration">3500</item>
    <item name="android:minWidth">48dip</item>
    <item name="android:maxWidth">48dip</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:maxHeight">48dip</item>
</style>


<style name="Widget.ProgressBar.RegularProgressBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/progressbar</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
    <item name="android:minHeight">1dip</item>
    <item name="android:maxHeight">10dip</item>
</style>

Custom View inside XML layout file:

<com.custom.ahmad.views.NfcProgressBar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/timeOutProgress"
    android:layout_above="@+id/tvStart"
style="@style/Widget.ProgressBar.RegularProgressBar" />

Finally The custom Progressbar class:

public class NfcProgressBar extends ProgressBar {

private String text = "";
private int textColor = Color.BLACK;
private float textSize = 15;

public NfcProgressBar(Context context) {
    super(context);
}

public NfcProgressBar(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public NfcProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected synchronized void onDraw(Canvas canvas) {

Drawable progressDrawable = this.getProgressDrawable();
    Log.i("Testing", "progressDrawable : " + ((progressDrawable != null) ? progressDrawable : "null"));
    Log.i("Testing", "progressDrawable instanceof LayerDrawable : " + ((progressDrawable instanceof LayerDrawable)? "true" : "false"));
    if (progressDrawable != null && progressDrawable instanceof LayerDrawable) {
        // Get the layer and do some programming work.
    }
}
0

There are 0 answers