Snake
Snake

Reputation: 14678

Wrap_content for custom progressbar always produces the same size

I am trying to use progress bar with two images in the background drwable( One is empty and one is full). I am using wrap_content. The problem is that the bar is much smaller than the image (if I use imageview it will be like 3 times). Even Itried to change the size of the image and the progress bar is still of the same size.

I don't want to set the width manually and I would rather go with wrap_content

<ProgressBar
            android:id="@+id/pbEnergyBar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="wrap_content"
            android:layout_height="29dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_centerHorizontal="true"
            android:progress="0"
            android:progressDrawable="@drawable/progress_bar_energy" />

Here is the background drawable

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

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/energy_backing"/>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/energy_full"/>

</layer-list>

Upvotes: 3

Views: 633

Answers (1)

Lucas Crawford
Lucas Crawford

Reputation: 3118

Try changing:

style=”?android:attr/progressBarStyleHorizontal”

to

style="@android:style/Widget.ProgressBar.Horizontal"

Upvotes: 0

Related Questions