Remove vertical padding from horizontal ProgressBar
I use the following as a workaround for this issue.
android:layout_marginBottom="-8dp"android:layout_marginTop="-4dp"
This is how I used Juozas's answer:
height of my ProgressBar
is 4dp. So I created a FrameLayout
with height 4dp and set the layout_gravity
of ProgressBar
to center
. It's works like a charm.
<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" android:indeterminate="true" /></FrameLayout>
Note: What a FrameLayout
does is it clips away anything excess, so if you face the problem where the ProgressBar
is still thin, just set the layout_height
of the ProgressBar
to some large number like 100dp
. It'll fully cover the FrameLayout and will only show 4dp
of it.
If someone still needs help can try this:
<androidx.core.widget.ContentLoadingProgressBar android:id="@+id/progress" android:layout_width="match_parent" android:layout_height="wrap_content" style="@style/Widget.AppCompat.ProgressBar.Horizontal" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline" android:indeterminate="true" android:visibility="visible" app:layout_constraintBottom_toTopOf="@+id/guideline" />
Here, the progress bar is inside the ConstraintLayout, and the constraintTop_toTopOf and constraintBottom_toTopOf attributes must be applied to the same element (in this case, it is guideline).
*** COMPLETE SOLUTION:***
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="48dp"> <View android:id="@+id/guideline" android:layout_width="0dp" android:layout_height="0dp" android:orientation="vertical" android:visibility="invisible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" /> <ProgressBar android:id="@+id/progress_bar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="true" app:layout_constraintBottom_toTopOf="@+id/guideline" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline" /></androidx.constraintlayout.widget.ConstraintLayout>