2017-11-21 1 views
0

나는 비슷한 질문을 herehere으로 읽었으며 모서리가 둥근 단일 진행률 표시 줄 만 표시하려는 경우 좋은 해결책이지만 내 경우에는 진행 상황을 보여주고 싶습니다. 내가 지금까지했던 어떤둥근 모서리와 여러 색상의 진행 표시 줄

progress bar

answer 같은이 LinearGradient 구현을 코딩하는 것입니다 있지만 모서리에 네모로 보이는 : 아래 그림처럼 여러 개의 "하위 진행"색상에서.

어떻게 진행할 수 있습니까?

답변

0

약간의 연구 끝에 어떤 뷰의 배경으로도 설정할 수있는이 클래스 PaintDrawable을 발견했으며 놀랍게도이 드로어 블에 셰이프를 설정할 수 있으므로 RoudRectShape을 사용하면 원하는대로 반올림 된 것처럼 보입니다. 최종 코드는 다음과 같습니다.

 // mRatios is a View 
     ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() { 
      @Override 
      public Shader resize(int i, int i1) { 
       LinearGradient lg = new LinearGradient(0, 0, mRatios.getWidth(), 0, 
         barColorsArray, 
         barRatiosArray, 
         Shader.TileMode.REPEAT); 

       return lg; 
      } 
     }; 
     PaintDrawable paintDrawable = new PaintDrawable(); 

     // not sure how to calculate the values here, but it works with these constants in my case 
     paintDrawable.setShape(new RoundRectShape(new float[]{100,100,100,100,100,100,100,100}, null, null)); 
     paintDrawable.setShaderFactory(sf); 
     if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { 
      mRatios.setBackgroundDrawable(paintDrawable); 
     } else { 
      mRatios.setBackground(paintDrawable); 
     }