Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align ProgressBar horizontal to top (remove gap) [duplicate]

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?

enter image description here

<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> 
like image 761
Pork 'n' Bunny Avatar asked Aug 30 '13 06:08

Pork 'n' Bunny


People also ask

Which attribute is used to display ProgressBar horizontally?

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.

What is ProgressBar in android?

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.

How many types of progress bar?

Progress bar supports two modes to represent progress: determinate, and indeterminate.


2 Answers

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" /> 
like image 113
bCliks Avatar answered Oct 02 '22 04:10

bCliks


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.

enter image description here

like image 28
Sathya Avatar answered Oct 02 '22 05:10

Sathya