Changing the size of the seekbar programmatically but cant get the thumb to be larger than the bar

前端 未结 1 2002
抹茶落季
抹茶落季 2020-12-06 07:26

I have to make a seekbar where i can change almost everything programmatically. And now I\'m having a problem to change the thumb and the bar size. Everything works great if

相关标签:
1条回答
  • 2020-12-06 08:01

    well, too bad there were no responses but i was able to answer the question myself. The answer is to use InsetDrawable. You have to put the one of the drawables of the bar into a InsetDrawable.

    Thats the code:

      public void setSeekBarProgress(int width, int height, int rColor, int gColor, int bColor){
            GradientDrawable shape2 = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{Color.WHITE,Color.rgb(rColor, gColor, bColor)});
            shape2.setCornerRadius(50);                     
            ClipDrawable clip = new ClipDrawable(shape2, Gravity.LEFT,ClipDrawable.HORIZONTAL);
    
            GradientDrawable shape1 = new GradientDrawable(Orientation.BOTTOM_TOP, new int[]{Color.WHITE, getResources().getColor(R.color.DimGray)});
            shape1.setCornerRadius(50);//change the corners of the rectangle    
            InsetDrawable d1=  new InsetDrawable(shape1,5,5,5,5);//the padding u want to use        
    
    
            LayerDrawable mylayer = new LayerDrawable(new Drawable[]{d1,clip});
    
    
            seekbar.setProgressDrawable(mylayer); 
    
            seekbar.setProgress(50);
    
      }
    

    I hope this can help someone else with the same problem.

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