Android “Advanced” Gradients - 'thumb' positions?

前端 未结 1 1030
南旧
南旧 2021-02-06 16:29

I am trying to create a gradient drawable to depict a ratio of something. As a general example, lets say you were looking at a listview containing a fleet of cars. The backgro

相关标签:
1条回答
  • 2021-02-06 17:05

    Ok, here's how you can do it:

    ShapeDrawable.ShaderFactory sf = new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            LinearGradient lg = new LinearGradient(0, 0, width, height,
                new int[]{Color.GREEN, Color.GREEN, Color.WHITE, Color.WHITE},
                new float[]{0,0.5f,.55f,1}, Shader.TileMode.REPEAT);
            return lg;
        }
    };
    
    PaintDrawable p=new PaintDrawable();
    p.setShape(new RectShape());
    p.setShaderFactory(sf);
    

    Then just set that as your backroundDrawable

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