Android: SeekBar with custom drawable

前端 未结 6 1236
独厮守ぢ
独厮守ぢ 2020-12-31 00:06

I have SeekBar with custom drawable. Progress element is not rendered from left side exactly but it is moved to right. How can I avoid this?



        
6条回答
  •  感动是毒
    2020-12-31 00:22

    Observation

    When you create a line using shape drawable it leaves the left and right padding (from the view in which this drawable is being used.)equal to the half of its stroke width.

    Workaround

    You need to wrap your progress_background with an inset drawable and then set it as progress background. The inset can be like the following-

    inset_seekbar_background.xml

    
    

    and your final seekbar.xml will be like-

    
    
    
        
        
            
        
    
    
    

    Alternates

    1.You can use an 9 path image for line as it is done in the default material design-

    
    
        
        
            
                
                    
                        
                    
                    
                
            
        
        
            
                
                    
                        
                    
                    
                
            
        
    
    

    2.You can set the theme to your view with different color in android style as-

    
    

    Here I have used all there options for Seekbars-

                
    
                
    
                
    

    And here is the output-

提交回复
热议问题