2

I am currently using a progressbar in my app, and at the top & bottom there's a padding that I want to remove. not sure it's even actually a padding.. you can see in the image below that there's white spaces above and below the pb itself.

Tried playing with it and ofc googled around and I saw lots of examples with custom drawables and similiar, is that the way? I was wondering what's the best practice to do that.. any suggestions?

My code right now (as simple as it gets):

<ProgressBar
    android:id="@+id/pc_progressbar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progressTint="@color/azure"/>

Adding an image to show the white spaces above & below the pb:

progressbarexample

JozeRi
  • 3,219
  • 6
  • 27
  • 45
  • Duplicate of [Remove vertical padding from horizontal ProgressBar](https://stackoverflow.com/questions/14171471/remove-vertical-padding-from-horizontal-progressbar) – Pilot_51 Dec 10 '19 at 17:54

3 Answers3

4

Set your height of your ProgressBar is 4dp. Created a FrameLayout with height 4dp and set the layout_gravity of ProgressBar to center.

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="4dp">

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:layout_gravity="center"/>

</FrameLayout>
SonhnLab
  • 321
  • 1
  • 11
  • Hi Sonhn, thanks for helping me! setting the height to 4dp does remove the white space at my device, no need for the frame layout.. wondering if this is the best solution tho, will it be the same for all device sizes? is this considered "best practice"? – JozeRi Jun 27 '18 at 10:52
  • Hi @JozeRi, you can choose the best solution in here https://stackoverflow.com/questions/14171471/remove-vertical-padding-from-horizontal-progressbar :D – SonhnLab Jun 27 '18 at 14:35
0

So you can using

<ProgressBar
    android:id="@+id/pc_progressbar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@null"
    android:paddingTop="@null"
    android:progressTint="@color/azure"/>

you can change the value to fit your layout.

or using this style

<style name="HorizontalProgressBarStyle" 
    parent="Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:background">@null</item>
    <item name="android:scaleY">@null</item>
    <item name="android:scaleX">@null</item>
    <item name="android:padding">@null</item>
</style>

hope this helps

GianhTran
  • 3,443
  • 2
  • 22
  • 42
  • 1
    hey buddy, first thanks a lot for trying to help! I'm not sure it's actually a padding issue, but anyway, your solution isn't working. – JozeRi Jun 27 '18 at 09:13
-1

For me this is working. Progress bar is sharp.

<FrameLayout             
    android:layout_width="match_parent"             
    android:layout_height="4dp">    

   <ProgressBar
       style="?android:attr/progressBarStyleHorizontal"
       android:layout_width="match_parent"
       android:layout_height="16dp"
       android:layout_gravity="center"
       android:indeterminate="true"/>
</FrameLayout>
pogo
  • 71
  • 2
  • 6