Android - set a ProgressBar to be a vertical bar instead of horizontal?

后端 未结 14 697
不知归路
不知归路 2020-11-30 22:22

I am trying to use a ProgressBar as a metering like display. I thought it was going to be an easy task and thought that ProgressBar had a property to set to be vertical, bu

14条回答
  •  日久生厌
    2020-11-30 23:10

    I found the probably best(easiest & most versatile) solution:)

    This is an old post, but it was so hard for me to find this so easy solution so I thought I should post it..

    Just use a scale-drawable (or a 9-patch if you want), no need for ANY OTHER code.

    Example:

      
    
          
    
        
            
                
                    
                    
                
            
        
      
    

    And of course the normal code:

      
    

    Notice the scale-drawable's xml lines (the magic lines):

    android:scaleGravity="bottom"  //scale from 0 in y axis (default scales from center Y)  
    android:scaleWidth="0%"        //don't scale width (according to 'progress')
    android:scaleHeight="100%"     //do scale the height of the drawable
    

提交回复
热议问题