jinreal
jinreal

Reputation: 1555

Bug occurs when implementing a vertical progress bar

I've implemented a vertical progress bar by extending the ProgressBar class. Everything works well except that it clear a large rect area that I don't intend to.

The definition of the progress bar in my main layout xml is:

<info.realjin.someapp.view.VerticalProgressBar
    android:id="@+id/progressbar1" android:layout_width="wrap_content"
    android:layout_height="fill_parent" android:layout_marginTop="50dip"
    style="@style/Widget.ProgressBar.RegularProgressBar" />

The style xml is:

<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">4dip</item>
    <item name="android:maxWidth">40dip</item>
    <item name="android:minHeight">4dip</item>
    <item name="android:maxHeight">400dip</item>
</style>

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

As far as I know, in a horizontal progress bar(the official progress bar) definition, the "android:layout_width" attribute should be "fill_parent" and the "android:layout_height" attribute should be "wrap_content". And in my vertical progress bar definition, I must define these two attributes inversely as above to get the bar functions well. But if I do this, all views between the top and bottom of the progress bar will be cleared as I mentioned in the beginning. How could I avoid it?

By the way, I've done an experiment---the area will be cleared even if the vertical progress bar class extends the official progress bar class with no methods overrided.

Upvotes: 0

Views: 174

Answers (1)

Robert
Robert

Reputation: 7053

I wrote a tutorial about this a while ago. http://www.androidenea.com/2011/10/creating-custom-view-part-1-graphics.html Feel free to use it as inspiration for your own code.

Without looking any further, I suspect your view is reporting the wrong measurements in onMeasure.

Upvotes: 0

Related Questions