Remove vertical padding from horizontal ProgressBar

后端 未结 22 1855
眼角桃花
眼角桃花 2020-11-28 03:30

By default the ProgressBar has a certain padding above and below the bar itself. Is there a way to remove this padding so as to only have the bar in the end?

相关标签:
22条回答
  • 2020-11-28 04:22

    Try the following:

    <ProgressBar
        android:id="@+id/progress_bar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:progress="25"
        android:progressTint="@color/colorWhite"
        android:progressBackgroundTint="@color/colorPrimaryLight"
        android:layout_width="match_parent"
        android:layout_height="4dp" />
    

    ... and then configure the progress bar to your needs since it'll initially display a mid-sized bar with a yellow-colored progress tint with a grayish progress background tint. Also, notice that there's no vertical padding.

    0 讨论(0)
  • 2020-11-28 04:23
    <androidx.core.widget.ContentLoadingProgressBar
                        android:id="@+id/progressBar"
                        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:indeterminate="true"
                        android:paddingTop="2dp"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toTopOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"/>
    
    0 讨论(0)
  • 2020-11-28 04:26

    if someone still searching for a solution -- check this comment

    set the minimum height to be 4 dp

       android:minHeight="4dp"
    

    -

      <ProgressBar
        android:id="@+id/web_view_progress_bar"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:max="100"
        android:min="0"
        android:progress="5"
        android:minHeight="4dp"
        android:progressTint="@color/vodafone_red"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:progress="60" />
    
    0 讨论(0)
  • 2020-11-28 04:27

    To remove the vertial padding of ProgressBar, you can do by

    • fix the height of ProgressBar
    • Use scaleY="value" (value = height/4) (4 is default height of progress bar)

    Example contains 1 wrap_content ProgressBar, 1 8dp ProgressBar, 1 100dp ProgressBar

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        ...
        android:layout_height="8dp"
        android:scaleY="2" />
    
    0 讨论(0)
提交回复
热议问题