How to set the Android progressbar's height?

前端 未结 11 1628
被撕碎了的回忆
被撕碎了的回忆 2020-12-08 03:40

My activity_main.xml is below, as you see, the height is set 40 dip.

And in MyEclipse, it looks like below:

相关标签:
11条回答
  • 2020-12-08 04:18

    Many solution here with lot of upvotes didn't work for me, even the accepted answer. I solved it by setting the scaleY, but isn't a good solution if you need too much height because the drawable comes pixelated.

    Programmatically:


    progressBar.setScaleY(2f);
    

    XML Layout:


    android:scaleY="2"
    
    0 讨论(0)
  • 2020-12-08 04:20

    This is the progress bar I have used.

    <ProgressBar
         android:padding="@dimen/dimen_5"
         android:layout_below="@+id/txt_chklist_progress"
         android:id="@+id/pb_media_progress"
         style="@style/MyProgressBar"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:progress="70"
         android:scaleY="5"
         android:max="100"
         android:progressBackgroundTint="@color/white"
         android:progressTint="@color/green_above_avg" />
    

    And this is my style tag

     <style name="MyProgressBar" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
        <item name="android:progressBackgroundTint">@color/white</item>
        <item name="android:progressTint">@color/green_above_avg</item>
    </style>
    
    0 讨论(0)
  • 2020-12-08 04:22

    values->styles.xml

    <style name="tallerBarStyle" parent="@android:style/Widget.SeekBar">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:minHeight">8dip</item>
        <item name="android:maxHeight">20dip</item>
    </style>
    

    Then in your ProgressBar add:

    style="@style/tallerBarStyle"
    
    0 讨论(0)
  • 2020-12-08 04:26

    I guess the simplest solution would be:

    mProgressBar.setScaleY(3f);
    
    0 讨论(0)
  • You can use the LinearProgressIndicator provided by the Material Components Library and the app:trackThickness attribute:

    <com.google.android.material.progressindicator.LinearProgressIndicator
        android:indeterminate="true"
        app:trackThickness="xxdp"
        ../>
    

    With 12dp:

    With 4dp:

    Note: it requires at least the version 1.3.0-alpha04.

    0 讨论(0)
提交回复
热议问题