79

My activity_main.xml is below, as you see, the height is set 40 dip.

And in MyEclipse, it looks like below:

enter image description here

But when I run it on my phone, it looks like below:

enter image description here

So my question is why the real height of the progressbar is not the one I set? How to increase the height of the progressbar?

mmBs
  • 7,728
  • 6
  • 37
  • 43
Tom Xue
  • 2,933
  • 6
  • 36
  • 59

11 Answers11

208

I guess the simplest solution would be:

mProgressBar.setScaleY(3f);
Martin Pfeffer
  • 11,627
  • 8
  • 54
  • 64
78

android:scaleY="8" in your xml file

Maksim Kniazev
  • 3,589
  • 26
  • 34
47

From this tutorial:

<style name="CustomProgressBarHorizontal" parent="android:Widget.ProgressBar.Horizontal">
      <item name="android:progressDrawable">@drawable/custom_progress_bar_horizontal</item>
      <item name="android:minHeight">10dip</item>
      <item name="android:maxHeight">20dip</item>
</style>

Then simply apply the style to your progress bars or better, override the default style in your theme to style all of your app's progress bars automatically.

The difference you are seeing in the screenshots is because the phones/emulators are using a difference Android version (latest is the theme from ICS (Holo), top is the original theme).

Sandeep Yohans
  • 726
  • 11
  • 27
Vincent Mimoun-Prat
  • 26,900
  • 13
  • 74
  • 118
21

Use this

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

Piraba
  • 6,288
  • 16
  • 79
  • 131
  • 15
    What does your answer have to do with setting custom height on the ProgressBar? – IgorGanapolsky Jun 15 '15 at 21:47
  • This solves the issue. Could you explain why this works? – 030 Sep 01 '15 at 12:25
  • 1
    @Alfred it works because the style is different. The drawn part of the Widget ProgressBar stretches to fit the entirety of layout_height, while the regular Android ProgressBar does not. – Chronicle Jan 13 '16 at 14:33
  • 2
    This solution works!! previously i was using `?android:attr/progressBarStyleHorizontal`, this doesnt work – Cheng Nov 22 '16 at 20:26
14

As mentioned in other answers, it looks like you are setting the style of your progress bar to use Holo.Light:

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

If this is running on your phone, its probably a 3.0+ device. However your emulator looks like its using a "default" progress bar.

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

Perhaps you changed the style to the "default" progress bar in between creating the screen captures? Unfortunately 2.x devices won't automatically default back to the "default" progress bar if your projects uses a Holo.Light progress bar. It will just crash.

If you truly are using the default progress bar then setting the max/min height as suggested will work fine. However, if you are using the Holo.Light (or Holo) bar then setting the max/min height will not work. Here is a sample output from setting max/min height to 25 and 100 dip:

max/min set to 25 dip: 25 dip height progress bar

max/min set to 100 dip: 100 dip height progress bar

You can see that the underlying drawable (progress_primary_holo_light.9.png) isn't scaling as you'd expect. The reason for this is that the 9-patch border is only scaling the top and bottom few pixels:

9-patch

The horizontal area bordered by the single-pixel, black border (green arrows) is the part that gets stretched when Android needs to resize the .png vertically. The area in between the two red arrows won't get stretched vertically.

The best solution to fix this is to change the 9patch .png's to stretch the bar and not the "canvas area" and then create a custom progress bar xml to use these 9patches. Similarly described here: https://stackoverflow.com/a/18832349

Here is my implementation for just a non-indeterminant Holo.Light ProgressBar. You'll have to add your own 9-patches for indeterminant and Holo ProgressBars. Ideally I should have removed the canvas area entirely. Instead I left it but set the "bar" area stretchable. https://github.com/tir38/ScalingHoloProgressBar

Community
  • 1
  • 1
tir38
  • 7,726
  • 6
  • 51
  • 84
11

Many solution here with lot of upvotes didn't work for me, even the accepted answer. I solved it by setting the scaleY, but isn't a good solution if you need too much height because the drawable comes pixelated.

Programmatically:


progressBar.setScaleY(2f);

XML Layout:


android:scaleY="2"
IgniteCoders
  • 3,538
  • 3
  • 34
  • 55
9
<ProgressBar  
android:minHeight="20dip" 
android:maxHeight="20dip"/>
Android Developer
  • 1,019
  • 1
  • 9
  • 30
4

values->styles.xml

<style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:minHeight">8dip</item>
    <item name="android:maxHeight">20dip</item>
</style>

Then in your ProgressBar add:

style="@style/tallerBarStyle"
Vincent Mimoun-Prat
  • 26,900
  • 13
  • 74
  • 118
Talha
  • 12,284
  • 4
  • 46
  • 65
4

This is the progress bar I have used.

<ProgressBar
     android:padding="@dimen/dimen_5"
     android:layout_below="@+id/txt_chklist_progress"
     android:id="@+id/pb_media_progress"
     style="@style/MyProgressBar"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="center"
     android:progress="70"
     android:scaleY="5"
     android:max="100"
     android:progressBackgroundTint="@color/white"
     android:progressTint="@color/green_above_avg" />

And this is my style tag

 <style name="MyProgressBar" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressBackgroundTint">@color/white</item>
    <item name="android:progressTint">@color/green_above_avg</item>
</style>
Jaiprakash Soni
  • 4,023
  • 4
  • 35
  • 66
Syeda
  • 368
  • 2
  • 11
4

You can use the LinearProgressIndicator provided by the Material Components Library and the app:trackThickness attribute:

<com.google.android.material.progressindicator.LinearProgressIndicator
    android:indeterminate="true"
    app:trackThickness="xxdp"
    ../>

With 12dp:

enter image description here

With 4dp:

enter image description here

Note: it requires at least the version 1.3.0-alpha04.

Gabriele Mariotti
  • 192,671
  • 57
  • 469
  • 489
0

You can set progress bar's style to this:

style="@android:style/Widget.ProgressBar.Horizontal"    
Rania
  • 1
  • 2