I'm trying to put a horizontal progress bar at the top of my frame. But there seems to be padding that I simply have been unable to remove. Any help?
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/flv_progress_bar" android:layout_width="fill_parent" style="@android:style/Widget.Holo.ProgressBar.Horizontal" android:indeterminateOnly="true" android:layout_height="wrap_content" android:layout_gravity="top"/> </FrameLayout>
In Android, by default a progress bar will be displayed as a spinning wheel but If we want it to be displayed as a horizontal bar then we need to use style attribute as horizontal. It mainly use the “android. widget. ProgressBar” class.
Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.
Progress bar supports two modes to represent progress: determinate, and indeterminate.
Pork'n'Bunny's answer worked API level 16 and up devices. This solution worked in all devices. Just push it by 6dp up in XML.
<ProgressBar android:id="@+id/progressbar_Horizontal" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="100" android:layout_alignParentTop="true" android:layout_marginTop="-6dp" />
from the looks of it, I think its caused by the image used in the default styling
style="@android:style/Widget.Holo.ProgressBar.Horizontal"
(the image I'm referring to is this one: @android:drawable/progress_indeterminate_horizontal_holo
and @android:drawable/progress_horizontal_holo_dark
)
These images have a lot of canvas background; therefore its showing this gap.
My recommendation:
use a custom image to style you PregressBar. One which doesn't have much canvas spacing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With